Alternate to sleeping NSThread for pause
Right now I'm sleeping my main thread in order to have my application pause before running an action. [NSThread sleepForTimeInterval:0.75];
. I know that that is less than ideal from a programming perspec开发者_StackOverflow社区tive, what other options do I have?
You could call the selector after a delay.
[self performSelector:@selector(yourAction:) withObject:nil afterDelay:0.75];
For applications targeted for devices with iOS 4.0 or greater you could use Grand Central Dispatch:
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, SecondsToWait*NSEC_PER_SEC), dispatch_get_current_queue(), ^{
// And Call Your Action Here.
});
精彩评论