嗨,我目前正在使用 core-plot 绘制动态图并且工作正常,现在我正在考虑在 2 个单独的视图上添加 2 个图
我已经开始使用 Mainview 绘图 Graph-1 和 Flipview 绘图 Graph-2 的“实用程序应用程序”
主视图图形工作正常,图形每 2 秒更新和重新加载一次,但是当我触摸“flipviewWindow”时,graph2 总是以新值和新的 graph2data 数组开始(可能是因为 graph2timer 再次被调用???)但是 graph1data只用一个 NSTimer 维护并且工作正常。
我不想释放这些值,因为我想查看具有先前值的图形,例如 Graph1。
有人可以建议如何通过动态数据更新在 2 个单独的 UIview 上实现 2 个核心绘图图吗?我的图形逻辑如下
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];
}