0

こんにちは、私は現在コアプロットを使用して動的グラフを描画しており、正常に機能しています。現在、2つの別々のビューに2つのグラフを追加することを考えています。

Mainview描画グラフ-1とFlipview描画Graph-2を使用した「ユーティリティアプリケーション」から始めました。

メインビューのグラフは正常に機能し、グラフは2秒ごとに更新および再読み込みされますが、「flipviewWindow」をタッチすると、graph2は常に新しい値と新しいgraph2data配列で始まります(おそらくgraph2timerが再度呼び出されるためですか?)がgraph1data 1つのNSTimerで維持し、正常に動作します。

Graph1のように以前の値でグラフを表示したいので、値を解放したくありません。

動的データ更新を使用して、2つの別々のUIビューに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];
}
4

1 に答える 1

0

データ フェッチをメイン コア プロットと分離することでサンプルを最適化し、データを更新するために NSNotification を追加しました。漏れの問題)。

また、「Show 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];
}
于 2011-05-08T23:06:34.783 に答える