我想在2.0秒後執行方法,但我希望能夠取消它,如果在5秒之前,如果另一個調用,但我注意到cancelPreviousPerformRequestsWithTarget
發送對象nil和performSelector發送對象NSString
。執行延遲後的方法並取消它
它會產生問題嗎?
-(void)startRecord:(NSString*)name {
if (self.needToStartRecording) {
//Cancel last call
[NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(startRecordAfterDelay:) object:nil];
}
self.needToStartRecording = YES;
[self performSelector:@selector(startRecordAfterDelay:) withObject:name afterDelay:5.0];
}
-(void)startRecordAfterDelay:(NSString*)name {
self.needToStartRecording = NO;
//Do My Stuff
}
http://stackoverflow.com/questions/3649273/iphone-how-to-cancel-stop-performselector – Rushabh