XCode 4.5、iPad 開発、iOS6
こんにちは、初心者の開発者を助けていただければ幸いです。これがすでに回答されている場合は事前にお詫びしますが、検索中に見つけることができませんでした!
Core Data に大量のデータをインポートする必要があるアプリを開発しています。インポート ルーチンは正常に動作します (ルーチンがバックグラウンドで動作している間、アラートはアクティビティ モニターで「お待ちください」と表示されます) が、ユーザーにインポートの進行状況に関するより詳細なフィードバック (「XX% インポート済み」など) を提供したいと考えています。次のコードはプロセスを開始し、-
- (IBAction)import:(id)sender{
[self showWaiting];
[self performSelectorInBackground:(@selector(callGrouper)) withObject:nil];
}
-(void)showWaiting{
alertMsg = @"Please Wait....";
waitAlert = [[UIAlertView alloc] initWithTitle:alertMsg message:nil delegate:self cancelButtonTitle:nil otherButtonTitles: nil];
[waitAlert show];
UIActivityIndicatorView *indicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
indicator.center = CGPointMake(waitAlert.bounds.size.width / 2, waitAlert.bounds.size.height - 50);
[indicator startAnimating];
[waitAlert addSubview:indicator];
}
-(void)callGrouper{
ImportRoutine *firstTest = [[ImportRoutine alloc] init];
[firstTest runImport:managedObjectContext];
[waitAlert dismissWithClickedButtonIndex:0 animated:TRUE];
UIAlertView *alert = [[UIAlertView alloc]initWithTitle: @"iPad Application"
message: @"Import complete!"
delegate: self
cancelButtonTitle:@"Ok"
otherButtonTitles:nil];
[alert show];
}
ImportRoutine (別のクラス) 内に、インポートされたパーセンテージに関するデータを収集するコードがありますが、このメッセージをメイン スレッドに戻して「alertMsg」を更新し、UIAlertView を更新するにはどうすればよいですか?