oc延时执行

/**延时执行*/
-(void)delay{
    //第一种
    [self performSelector:@selector(start) withObject:nil afterDelay:2.0];
    
    //第二种 可以重复调用
    [NSTimer scheduledTimerWithTimeInterval:2.0 target:self selector:@selector(start) userInfo:nil repeats:YES];
    
    /**第三种  可以在主线程 或者自线程中执行
     第一个参数 从现在开始计时
     第二个参数 延时的时间 单位纳秒
     第三个参数队列
     
     */
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t) (2.0*NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        
    });
    
}

猜你喜欢

转载自blog.csdn.net/u014029960/article/details/79157648