标签:blog 使用 io for ar div log sp on
使用 NSTimer 和 perfrormSelectorOnMainThread:withObject:waitUntilDone 做定时并可以取消移除:
-(void)viewDidAppear:(BOOL)animated { [super viewDidAppear:animated]; [self performSelectorOnMainThread:@selector(autoRefreshRecentDoctorAdvices) withObject:nil waitUntilDone:NO]; } //自动刷新 -(void)autoRefreshRecentDoctorAdvices { //_timer 是对象的私有变量,以便取消定时 _timer = [NSTimer scheduledTimerWithTimeInterval:100 target:self selector:@selector(getRecentDoctorAdvices) userInfo:nil repeats:YES]; } //取消定时,并移除 performSelector -(void) cancelTimer { if( _timer) { [_timer invalidate]; [NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(autoRefreshRecentDoctorAdvices) object:nil]; return; } }
标签:blog 使用 io for ar div log sp on
原文地址:http://www.cnblogs.com/1oo1/p/3940090.html