NSRunLoop的使用场景

1.应用一:定时器与滚动事件

[NSRunLoop currentRunLoop] addTimer:timer forMode:NSRunLoopCommonModes];


2.应用二:异步请求与滚动事件

NSURLConnection *connection = [NSURLConnection alloc] initWithRequest:request delegate:self startImmediately:NO];

[connection scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSRunLoopCommonModes];

[connection start];


3.应用三:子线程中添加异步请求

在子线程中添加:

while (1) {

[NSRunLoop currentRunLoop] runMode:NSDetaltRunLoopMode beforeDate:[NSDate distantFuture];

}

你可能感兴趣的:(ios,NSRunLoop)