1. 程式人生 > >iOS延遲執行的三種方法

iOS延遲執行的三種方法

    第一種:

[selfperformSelector:@selector(afterDelayMethod) withObject:selfafterDelay:3];

第二種:

//[NSThread sleepForTimeInterval:3];//主執行緒沉睡3

第三種:

double delayInSeconds = 10.0;

dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC));

dispatch_after(popTime, dispatch_get_main_queue

(), ^(void){

NSLog(@"電充好了");

        finishBlock();

    });