在iOS4中,有没有一种方法可以在延迟后使用NSThread以外的东西调用方法,或者使用sleep()阻塞UI?
发布于 2011-07-13 03:49:56
double delayInSeconds = 2.0;
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC);
dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
// code to be executed on main thread.If you want to run in another thread, create other queue
});
发布于 2011-07-12 22:08:33
- (void)performSelector:(SEL)aSelector withObject:(id)anArgument afterDelay:(NSTimeInterval)delay
将会为你做这件事。
此外,您还可以创建一个NSTimer
,并让它在给定的时间后回调某个目标和选择器。
发布于 2011-07-12 22:08:40
您可以使用NSTimer。(例如timerWithTimeInterval:target:selector:userInfo:repeats
)
https://stackoverflow.com/questions/6665467
复制相似问题