2014-12-21 30 views
0
開始

我不知道這是可能的...我有這樣的代碼在touchesEnded:我怎樣才能取消touchesEnded代碼時的touchesBegan再次

[self performSelector:@selector(GameOver) withObject:nil afterDelay:3]; 

但是,如果前3再次觸摸屏幕秒數到了,我想取消GameOver的調用。任何想法我可以做到這一點。

在的touchesBegan,我想是這樣的:

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

這沒有奏效。

+0

這不是你問過同樣的問題? http://stackoverflow.com/questions/27585523/how-to-call-gameover-after-3-second-unless-touchesbegan-again – matt

+0

是啊哈哈我只是想重寫它,因爲我決定我想採取一個單獨的方法...我刪除了那一個。 – Alex

回答

0

您的selector價值在您的cancelPreviousPerformRequestsWithTarget調用中是錯誤的,就是這樣。如果performSelector中的原始選擇器是GameOver那麼顯然您要取消的執行請求必須指定爲GameOver

這是從文檔非常清楚:https://developer.apple.com/library/ios/documentation/Cocoa/Reference/Foundation/Classes/NSObject_Class/index.html#//apple_ref/occ/clm/NSObject/cancelPreviousPerformRequestsWithTarget:selector:object

+0

請不要用這樣的大寫字母來命名'GameOver'方法,再次,好嗎?它只是惹惱了青蛙。 – matt

+0

非常感謝。這解決了它!對於我的編碼感到抱歉,我對此有點新。 – Alex

相關問題