您的位置:首页 > 移动开发 > IOS开发

iOS-定时任务

2016-03-02 14:39 441 查看
定时任务就是一定时间内或一定时间之后做某事,一共三个方法。

现在需要执行的操作是,2秒之后执行begin这个方法。

第一种方法:

<pre name="code" class="objc">
[self performSelector:@selector(begin) withObject:nil afterDelay:2];



第二种方法:用多线程GCD方法

<pre name="code" class="objc">
dispatch_after(dispatch_time(DISPATCH_TIME_NOW,(int64_t)(22* NSEC_PER_SEC)),dispatch_get_main_queue(),^{

self.hud.alpha=0.0

});


第三种发放:用NSTimer

<pre name="code" class="objc">
[NSTimer scheduledTimerWithTimeInterval:2 target:self selector:@selector(begin)userInfo:nil repeats:NO];
// repeats如果为YES,每隔2秒就会调用一次begin方法


                                            
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: