Objective-C 鍐呭瓨绠$悊娴呮瀽涓庡惊鐜己寮曠敤涓句緥
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Objective-C 鍐呭瓨绠$悊娴呮瀽涓庡惊鐜己寮曠敤涓句緥相关的知识,希望对你有一定的参考价值。
鏍囩锛?/p>
鐞嗚В
- 鍙橀噺
- 浣滅敤鍩?/li>
- 鍙橀噺搴熷純
- 鎸佹湁瀵硅薄
- 閲婃斁瀵硅薄
- 瀵硅薄鎵€鏈夎€咃紙寮曠敤璁℃暟锛?/li>
- 瀵硅薄搴熷純
- 鍙橀噺鎵€鏈夋潈淇グ绗﹀瀵硅薄鐨勫奖鍝?/li>
瀵硅薄鐩镐簰鎸佹湁瀵艰嚧寰幆寮哄紩鐢紝涓句緥濡傚弽澶嶆墽琛屼换鍔$殑NSTimer瀵硅薄鐨勭洰鏍囧璞?br /> 鍙堜繚鐣欎簡璁℃椂鍣ㄥ璞★紝鑻ヨNSTimer瀵硅薄琚洰鏍囧璞℃寔鏈夛紝渚垮繀瀹氫細鍙戠敓寰幆寮哄紩鐢紝鍥犱负NSTimer瀵硅薄浼氭寔鏈夌洰鏍囷紝
鑰岃NSTimer瀵硅薄鍙堟槸鐩爣瀵硅薄鐨勬垚鍛樺彉閲忎篃灏辨槸鐩爣瀵硅薄鍙堟寔鏈夎NSTimer瀵硅薄
姝ゅ惊鐜己寮曠敤浼氫竴鐩存寔缁埌鐩爣瀵硅薄璋冪敤NSTimer瀵硅薄鐨刬nvalidate鏂规硶閲婃斁璇STimer瀵硅薄
鍙€氳繃鎵╁睍NSTimer绫诲埄鐢╞lock涓巁_weak鎵€鏈夋潈淇グ绗﹁В鍐宠寰幆寮哄紩鐢?/p>
#import<Foundation/Foundation.h> @interface NSTimer(BlocksSupport) +(NSTimer *)scheduledTimerWithTimeInterval: (NSTimeInterval)interval block:(void(^)())block repeats:(BOOL)repeats; @end @implementation NSTimer(BlockSupport) +(NSTimer *)scheduledTimerWithTimeInterval: (NSTimeInterval)interval block:(void(^)())block repeats:(BOOL)repeats { return [self scheduledTimerWithTimeInterval:interval target:self selector:@selector(blockInvoke:) userInfo:[block copy] repeats:repeats]; } +(void)blockInvoke:(NSTimer *)timer{ void(^block)()=timer.userInfo; if(block){ block(); } }
//鍦ㄥ埆鐨凜lass绫讳娇鐢ㄧ殑鏃跺€?/span> -(void)startAction{ __weak Class *weakSelf=self;//瀹氫箟涓€涓寚鍚戣嚜宸辩殑寮卞紩鐢?/span> _myTimer=[NSTimer scheduledTimerWithInterval:5.0 block:^{ Class *strongSelf=weakSelf;/*鍧楁崟鑾疯鎸囧悜鑷繁鐨勫急寮曠敤锛屼笉鐩存帴鎹曡幏鏅€氱殑self鍙橀噺锛屽洜姝lock涓嶆寔鏈夎Class瀵硅薄 鐒跺悗椹笂璁_strong鍙橀噺鎸佹湁璇_weak鐨凜lass瀵硅薄淇濊瘉瀹炰緥鍦ㄦ墽琛屾湡闂存寔缁瓨娲伙紝 涔熷氨鏄strongSelf涔熸槸鎸佹湁浜咰lass瀵硅薄鐨勶紝浣嗘槸锛屼絾鏄紝浣嗘槸锛宻trongSelf鏄湪block浣? 涓0鏄庣殑鍙橀噺锛屽叾鐢熷懡鍛ㄦ湡浠呭瓨block鍧楋紝鍦╞lock鍧楁墽琛屽畬鍚庝究閲婃斁锛屼篃灏变笉鎸佹湁Class瀵硅薄浜?/span>*/ [strongSelf excueAction]; } repeats:YES]; } -dealloc{ [_myTimer invalidate];/*褰撳鐣屾寔鏈塁lass瀵硅薄鐨勬渶鍚庝竴涓紩鐢ㄥ皢鍏堕噴鏀剧殑鏃跺€欙紝璇ユ柟娉曚細琚墽琛岋紝浠庤€岃繕浼氳璁℃椂鍣ㄥ仠姝㈠伐浣溿€? 鑻ュ紑鍙戣€呭繕璁板湪dealloc涓皟鐢╥nvalidate鏂规硶鍋滄璁℃椂鍣紝閭d箞璁℃椂鍣ㄦ墽琛岀殑block鍧椾腑鐨剋eakSelf浼氬彉鎴恘il strongSelf涔熷氨鎸囧悜浜唍il锛屼粠鑰岃鏃跺櫒鎵ц绌烘搷浣溿€?/span>*/ }
以上是关于Objective-C 鍐呭瓨绠$悊娴呮瀽涓庡惊鐜己寮曠敤涓句緥的主要内容,如果未能解决你的问题,请参考以下文章
鐮佸啘鎵嬭 | Spring WebFlux瀹炴垬浠ュ強鍘熺悊娴呮瀽
520蹇箰~ 娴呮瀽 Vue.js 涓偅浜涚┖闂存崲鏃堕棿鐨勬搷浣滐紙濂芥枃鏀惰棌锛侊級