是个小知识点,大家对于这个方法都不陌生把,就是最后调回主线程的。那么最后一个参数是干嘛呢?很简单,我们来看一段代码:
注意时间,打印3333333是立即打印的,如果我改成yes,什么结果呢?
相信大家明白了,333333在执行完2222222才执行,所以这个就是yes,代表要等到selector方法执行完,才会继续执行。
- (void)beginWirte
{
NSLog(@"11111111");
[self performSelectorOnMainThread:@selector(beginread) withObject:nil waitUntilDone:NO];
NSLog(@"33333333");
}
- (void)beginread
{
sleep(10);
NSLog(@"2222222");
}
这时候是no
2014-03-03 16:03:07.427 perfomDemo[8841:330b] 11111111
2014-03-03 16:03:07.427 perfomDemo[8841:a0b] Application windows are expected to have a root view controller at the end of application launch
2014-03-03 16:03:07.429 perfomDemo[8841:330b] 33333333
2014-03-03 16:03:17.433 perfomDemo[8841:a0b] 2222222
注意时间,打印3333333是立即打印的,如果我改成yes,什么结果呢?
2014-03-03 16:08:09.313 perfomDemo[8858:a0b] Application windows are expected to have a root view controller at the end of application launch
2014-03-03 16:08:09.311 perfomDemo[8858:3407] 11111111
2014-03-03 16:08:19.318 perfomDemo[8858:a0b] 2222222
2014-03-03 16:08:19.320 perfomDemo[8858:3407] 33333333
相信大家明白了,333333在执行完2222222才执行,所以这个就是yes,代表要等到selector方法执行完,才会继续执行。