백그라운드 처리가 진행되는 동안 UIActivityIndicatorView를 표시하려고합니다. 아래의 간단한 코드는 시뮬레이터에서 시도 할 때 작동합니다 (경고가 표시됨). 그러나 Xcode에서 내 전화기로 다운로드하면 배경 스레드가 전혀 호출되지 않는 것 같습니다. (경고가 표시되지 않음)
아이디어가 있으십니까?스레딩은 시뮬레이터에서 작동하지만 iPhone에서는 작동하지 않습니다.
-(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];
}
또한 멀티 스레딩의 경우 NSOperation 및 NSOperationQueue를 조사 할 가치가 있습니다. 정말 인생을 훨씬 편하게 해줍니다. – nduplessis