如何取消performSelectorOnMainThread?

时间:2012-04-17 19:19:42

标签: iphone objective-c xcode cocoa-touch nsthread

如何取消performSelectorOnMainThread

我有这段代码:

myClass = [[MyClass alloc] init];

[myClass performSelectorOnMainThread:@selector(setupPlayer) withObject:nil waitUntilDone:YES];

2 个答案:

答案 0 :(得分:3)

根据documentation

  

您无法取消使用此方法排队的邮件。

答案 1 :(得分:2)

如果您对最初对邮件进行排队的帖子非常小心,那么可以通过在同一个线程上调用+ (void)cancelPreviousPerformRequestsWithTarget:(id)aTarget来取消它。之前的答案错过了重要的一点:

  

您无法取消使用此方法排队的邮件。如果你想要的话   要取消当前线程上的消息,必须使用   performSelector:withObject:afterDelay:或   performSelector:withObject:afterDelay:inModes:method。

相关问题