performSelectorInBackground:
中有方法performSelector: afterDelay:
和NSObject
。如何在一行代码中组合它们?
也许以某种方式NSTimer
?
答案 0 :(得分:13)
您是否考虑过使用块?
double delayInSeconds = 2.0;
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC);
dispatch_after(popTime, dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0),
^(void){
//your code here
});
另外,如果写作太多,那么已经有了它的片段,开始输入" dispatch_after"而且你会看到它。
答案 1 :(得分:-1)
NSTimer
[NSTimer scheduledTimerWithTimeInterval:2.0
target:self
selector:@selector(targetMethod:)
userInfo:nil
repeats:NO];