XCode 4.5、iPad 开发、iOS6
嗨,我希望你能帮助一个新手开发者!如果已经回答了这个问题,但我在搜索过程中找不到,请提前道歉!
我正在开发一个需要将大量数据导入核心数据的应用程序。导入例程工作正常(警报显示“请稍候”和活动监视器,而例程在后台运行)但我想向用户提供有关导入进度的更详细的反馈(例如“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?