兩折的問題:我在一個正確的/高效的莊園使用afterDelayafterDelay效率和cancelPreviousPerformRequestsWithTarget
是誰?我是新來的Objective-C,所以只是想確保我正確使用它。
每當在時間到了之前再次調用它時,它會開始運行兩種方法(這是有道理的)。經過一番研究後,我發現cancelPreviousPerformRequestWithTarget,但它似乎取消了再次調用該方法的能力。我不確定是否有更好的方法來處理這個問題。
[self beginShow:5 myIncrease:0.1]; - (void)beginShow:(CGFloat)duration myIncrease:(CGFloat)myIncrease{ CGFloat currentTime = 0.0; while(duration > currentTime){ [self performSelector:@selector(setRed) withObject:nil afterDelay:currentTime]; [self performSelector:@selector(setTorchToLevelOn) withObject:nil afterDelay:currentTime]; currentTime = currentTime+myIncrease; [self performSelector:@selector(setBlack) withObject:nil afterDelay:currentTime]; [self performSelector:@selector(setTorchToLevelOff) withObject:nil afterDelay:currentTime]; currentTime = currentTime+myIncrease; [self performSelector:@selector(setPurple) withObject:nil afterDelay:currentTime]; [self performSelector:@selector(setTorchToLevelOn) withObject:nil afterDelay:currentTime]; currentTime = currentTime+myIncrease; [self performSelector:@selector(setDefault) withObject:nil afterDelay:currentTime]; [self performSelector:@selector(setTorchToLevelOff) withObject:nil afterDelay:currentTime]; currentTime = currentTime+myIncrease; } }
這是給我的未申報選擇。但是,當我參考另一個沒有參數的方法時,它可以工作。有什麼想法嗎? '[NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(beginShow)object:nil];' –