如何在cocos2d中禁用选择器的函数调用?

时间:2011-11-15 08:38:58

标签: iphone cocos2d-iphone selector

我在选择器中设置了一个功能。函数调用后我想不调用选择器。我写了这行代码,但它抛出异常:

self.touchselector = nil;

如何在cocos2d中重置选择器的功能?

2 个答案:

答案 0 :(得分:0)

试试这个:

[NSNotification cancelPreviousPerformRequestsWithTarget:self selector:@selector(powerHide) object:nil];

答案 1 :(得分:0)

假设您按照与此类似的方式安排了一个选择器:

[self scheduleSelector:@selector(onTouch:) interval:1];

然后,您可以通过_cmd:

在其调用的方法中取消调度该特定选择器
-(void) onTouch:(ccTime)delta
{
    // this will stop onTouch from being called every second
    [self unscheduleSelector:_cmd];
}