3

如果我在 UIView 的子类中这样做:

[self performSelector:@selector(doSomething) withObject:nil afterDelay:5];

然后像这样取消它(我已经尝试了两个版本):

 [[NSRunLoop currentRunLoop] cancelPerformSelectorsWithTarget:self];
 //[[NSRunLoop mainRunLoop] cancelPerformSelectorsWithTarget:self];

“doSomething”方法仍然被调用。我究竟做错了什么?

4

1 回答 1

1

在 NSObject 类参考中:

cancelPreviousPerformRequestsWithTarget:selector:object:

取消之前使用 performSelector:withObject:afterDelay: 注册的执行请求。

利用:

[NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(doSomething) object:nil];

希望这可以帮助。

于 2010-10-21T22:59:34.207 回答