1.延遲一段時(shí)間執(zhí)行某段代碼
[self performSelector:@selector(delayFunctionCode)
withObject:nil
afterDelay:3.0];
2.取消延遲要執(zhí)行的代碼
[NSObject cancelPreviousPerformRequestsWithTarget:self
selector:@selector(delayFunctionCode)
object:nil];
Tip:若有參數(shù),取消時(shí)參數(shù)要一致(我這里沒(méi)加參數(shù))