NSObject cancelPreviousPerformRequestsWithTarget任何对象

时间:2014-03-02 18:28:54

标签: ios objective-c nsobject

我目前正在使用

[NSObject cancelPreviousPerformRequestsWithTarget:self];

取消doneMoving:的performSelector。这会导致问题,因为我有其他performSelectors在运行,我想要取消。解决方案是使用

[NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(doneMoving:) object:objectIDontKnow];

但我不知道使用原始performSelector传递的对象。我希望能够取消所有doneMoving:请求,无论传递什么对象,同时仍然保持我的其他预定方法。谢谢!

1 个答案:

答案 0 :(得分:-1)

尝试以不同的方式重写代码,因此您不会传递对象

- (void)moveObject {

    [self.objectToMove doSmth];

}

- (void)performMoveObjectInFuture:(id)moveObject {

    self.objectToMove = moveObject;
    [self performSelector:@selector(moveObject) withObject:nil afterDelay:2];

}