IOS5.1 アプリで CorePlot-Cocoa Touch を利用する。散布図、dataForPlots、凡例などの設定には時間がかかるため、ユーザーに何かが起こっていることを示すために UIActivityIndicatorView を含めることにしました。
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
progressInd = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
progressInd.center = self.view.center;
[progressInd sizeToFit];
progressInd.hidden = NO;
progressInd.alpha = 1.0;
[self.view addSubview:progressInd];
[progressInd startAnimating];
[self.view bringSubviewToFront:progressInd];
[self performSelectorInBackground:@selector(DoMakeupPlot) withObject:nil];
}
- (void)DoMakeupPlot
{
… set up plot
… including datasource and delegate
[progressInd stopAnimating];
[progressInd removeFromSuperview];
progressInd = nil;
}
現在、これは時々機能するように見えますが、プロット データソース ルーチンを呼び出す 2 つのスレッドがあることは明らかです。
-(NSUInteger)numberOfRecordsForPlot:(CPTPlot *)プロット
-(NSNumber *)numberForPlot:(CPTPlot *)plot フィールド:(NSUInteger)fieldEnum recordIndex:(NSUInteger)index
これにより、メモリの問題が発生し、アプリがクラッシュすることがあります。
上記の 2 つのルーチン内からこれら 2 つのスレッドを終了することを実験しましたが、これにより別の問題が発生します。
上記の 2 つのルーチンが MainThread から呼び出されるこの UIActivityIndicatorView を使用する前であれば、すべて問題ありません。
MBProgressHud でもこれを試してみましたが、明らかに同じ問題があります。
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
HUD = [[MBProgressHUD alloc] initWithView:self.view];
[self.view addSubview:HUD];
HUD.delegate = self;
HUD.labelText = @"Loading";
HUD.detailsLabelText = @"plot data";
HUD.square = YES;
[HUD showWhileExecuting:@selector(DoMakeupPlot) onTarget:self withObject:nil animated:YES];
}
セットアップが完了した後、MainThread が UIActivityIndicatorView を実行しているときに、数値計算を実行する Thread を削除するにはどうすればよいですか?
助けていただければ幸いです。