[ios]ios的順延強制方法,ios順延強制方法

來源:互聯網
上載者:User

[ios]ios的順延強制方法,ios順延強制方法
1.最直接的方法performSelector:withObject:afterDelay:這種方法的缺點:每次要為延時寫一個方法 2.使用類別,用BOLCK執行[代碼]c#/cpp/oc代碼:

01 @implementation NSObject (PerformBlockAfterDelay)
02  
03 - (void)performBlock:(void (^)(void))block
04           afterDelay:(NSTimeInterval)delay
05 {
06     block = [[block copy] autorelease];
07     [self performSelector:@selector(fireBlockAfterDelay:)
08                withObject:block
09                afterDelay:delay];
10 }
11  
12 - (void)fireBlockAfterDelay:(void (^)(void))block {
13     block();
14 }
15  
16 @end
 3.使用GCD[代碼]c#/cpp/oc代碼:
1 void RunBlockAfterDelay(NSTimeInterval delay, void (^block)(void))
2 {
3     dispatch_after(dispatch_time(DISPATCH_TIME_NOW, NSEC_PER_SEC*delay),
4       dispatch_get_current_queue(), block);
5 }
poolo:注意 圖中的dispatch_getcurrent_queue() 方法在ios6已經被kill了現在用dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH,0)第一個參數是優先順序有,第二個參數為0或nil如果要要對介面操作則使用dispatch_get_main_queue();參考:http://www.cnblogs.com/guwandong/archive/2012/08/08/2626211.html 4.可能是不太好的方法,用animation的completion參數[代碼]c#/cpp/oc代碼:
1 [UIView animateWithDuration:0.0 delay:5.0 options:UIViewAnimationOptionAllowUserInteraction animations:^{
2 } completion:^(BOOL finished) {
3     //do stuff here
4 }];
 5.使用NSOperationQueue,在應用程式的下一個主迴圈執行:[代碼]c#/cpp/oc代碼:
1 [[NSOperationQueue mainQueue] addOperationWithBlock:aBlock];
 這個和調用performSelector: with afterDelay of 0.0f等價
iOS 怎實現一個函數自己設定時間來完成,例如執行-(void)stop;需要5秒,那怕裡面什都不執行

[self performSelector:@selector(函數名) withObject:nil afterDelay:5.0f]
條件:在uiviewController的主線程中
[NSTimer scheduledTimerWithTimeInterval:5.0f target:self selector:@selector(函數名) userInfo:nil repeats:NO];在具體函數中,執行代碼,執行完畢以後調用NSTimer invalidate方法來銷毀timer
[NSThread sleepForTimeInterval:5.0f];[要順延強制的方法];
條件:主線程或者子線程都可

 
IOS開發UITableView的didSelectRowAtIndexPath方法延遲問題

點擊cell做了什麼操作?做的操作複雜嗎?如果什麼都沒有操作的話,應該會馬上響應的。請問一下用的靜態表是什麼意思啊?機器不好也有關係,如果你的資料不多,應該會馬上響應的,如果你點擊cell做了響應彈出一個頁面,並且這個頁面的初始化很複雜的話,不會馬上彈出的。
 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.