我正在尝试在进行后台处理时显示 UIActivityIndicatorView 。下面的简化代码在我在模拟器中尝试时有效(显示警报)..但是当我从 Xcode 将它下载到我的手机时,后台线程似乎根本没有被调用。(警报永远不会显示)有
什么想法吗?
-(void)viewDidLoad {
[self performSelectorInBackground:@selector(runInAnotherThread) withObject:nil];
}
-(void) runInAnotherThread {
NSAutoreleasePool *pool = [ [ NSAutoreleasePool alloc ] init ];
int i;
for(i=0;i < 1000 ;i ++){
NSLog(@"INDEX = %d", i);
}
[self performSelectorOnMainThread : @ selector(backToMainThread ) withObject:nil waitUntilDone:NO];
[ pool release ];
}
-(void) backToMainThread {
UIAlertView *completeAlert = [[UIAlertView alloc]
initWithTitle:@"Back to main "
message: @"Success"
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[completeAlert show];
[completeAlert release];
}