귀하의 경우에 맞게 코드를 적용 할 수 있습니다. 기본적으로 루프를 여러 메시지로 "언 롤링"합니다. [self doItForIndex:[NSNumber numberWithInt:0]];
- (BOOL)canDoitForIndex:(NSNumber *)i {
// return YES if you want to go ahead
// (e.g. test a BOOL you set in response to the user tapping a button
}
- (void)waitForIndex:(NSNumber *)i {
if ([self canDoItForIndex:i]) {
// do anything to clean up for i
// then repeat for i+1:
[self doItForIndex:[NSNumber numberWithInt:[i intValue]+1]];
} else {
[self performSelector:_cmd withObject:i afterDelay:0.01f;
}
}
- (void)doItForIndex:(NSNumber *)i {
if ([i intValue] < lastIndex) {
// do what you have to do
[self waitForIndex:i];
}
// else you're done
}
애플의 NSRunLoop
개념 순서를 시작하면 꽤 빨리 처리를 완료 할 예정이다. 당신이 뭔가를 기다려서 메인 스레드를 묶는다면, 당신의 앱에있는 어떤 것도 일어날 수 없다. 위의 코드는 "대기"를 여러 메시지 전송으로 나누고 앱의 반응을 유지합니다.
많은 도움을 주셔서 감사합니다. –