嗨,我目前正在使用core-plot来绘制一个动态图形,并且工作正常,现在我正在考虑在2个独立的视图上添加2个图形
我已经开始使用-1\f25 Mainview drawing Graph-1 \f6和-1\f25 Flipview drawing Graph-2 \f6的-1\f25 Utility Application-1\f6(实用程序
主视图图形运行良好,并且图形每2秒更新和重新加载一次,但是当我触摸"flipviewWindow“时,graph2总是以新值和新的graph2data数组开始(可能是因为graph2timer被再次调用?)但graph1data只使用一个NSTimer进行维护,并且运行良好。
我不想释放这些值,因为我希望看到具有先前值的图形,就像在Graph1中一样。
有人可以建议如何在两个独立的UIviews上实现动态数据更新的两个核心图吗?我的图逻辑如下
In MainViewController.m
-(void)viewDidLoad{
[super viewDidLoad];
[self ConstructGraph1]
}
-(void)ConstructGraph1 {
graph1 = [[CPXYGraph alloc] initWithFrame:CGRectZero];
CPTheme *theme = [CPTheme themeNamed:kCPStocksTheme];
[graph1 applyTheme:theme];
mainViewWindow.hostedGraph=graph1;
.
.
.
.
.
myTimer1=[NSTimer scheduledTimerWithTimeInterval:2 target:self selector:@selector(graph1Timer:) userInfo:nil repeats:YES];
}
-(void) graph1Timer: (NSTimer *) Timer{
NSTimeInterval aTimeInterval1 = [[NSDate date]
timeIntervalSinceReferenceDate];
Get JSON request and add object at every 2 sec, after succesfully fetching
[graph1data addObject:...]
[graph1 reloadData];
}
- (void)flipsideViewControllerDidFinish:(FlipsideViewController *)controller
{
[self dismissModalViewControllerAnimated:YES];
}
- (IBAction)showFlipWindow:(id)sender
{
FlipsideViewController *controller = [[FlipsideViewController alloc] initWithNibName:@"FlipsideView" bundle:nil];
controller.delegate = self;
controller.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:controller animated:YES];
[controller release];
}
In FlipViewController.m
-(void)viewDidLoad{
[super viewDidLoad];
self.view.backgroundColor = [UIColor viewFlipsideBackgroundColor];
[self ConstructGraph2]
}
//ConstructGraph2 uses the same logic to draw the graph and to fetch the results
-(void) ConstructGraph2 {
graph2 = [[CPXYGraph alloc] initWithFrame:CGRectZero];
CPTheme *theme = [CPTheme themeNamed:kCPStocksTheme];
[graph1 applyTheme:theme];
mainViewWindow.hostedGraph=graph1;
.
.
.
.
.
myTimer2=[NSTimer scheduledTimerWithTimeInterval:2 target:self selector:@selector(graph2Timer:) userInfo:nil repeats:YES];
}
-(void) graph2Timer: (NSTimer *) Timer{
NSTimeInterval aTimeInterval2 = [[NSDate date]
timeIntervalSinceReferenceDate];
Get JSON request and add object at every 2 sec, after succesfully fetching
[graph2data addObject...];
[graph2 reloadData];
}
- (IBAction)showMainWindow:(id)sender
{
[self.delegate flipsideViewControllerDidFinish:self];
}发布于 2011-05-09 07:06:35
我已经优化了我的示例,将数据获取与主核心图分开,并为数据中的更新添加了NSNotification,我遇到了内存泄漏(http://stackoverflow.com/questions/5927476/yajl-memory-leak-problem)的一些问题。
另外,我对控制器做了以下更改,这样它就不会在每次按下“显示Grpah2”时重新加载整个图形。
if(controller==nil){
controller=[[FlipsideViewController alloc] initWithNibName:@"FlipsideViewController" bundle:nil];
controller.delegate = self;
controller.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:controller animated:YES];
}
else{
controller.delegate = self;
controller.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:controller animated:YES];
}https://stackoverflow.com/questions/5868112
复制相似问题