1,创建一个新的子线程
2,如果不在主线程中,将其加入主线程
3,使用闭包
还有很多,delegate的函数,用到在做补充
//在分线程中操作
[NSThread detachNewThreadSelector:@selector(saveUserData) toTarget:self withObject:nil];
2,如果不在主线程中,将其加入主线程
//如果当前非主线程,将其加入主线程
if (![NSThread isMainThread])
{
[self performSelectorOnMainThread:@selector(loginSuccess) withObject:nil waitUntilDone:NO];
return;
}
3,使用闭包
//添加一个子线程
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
//读取文件
NSString *fileURL = [NSString stringWithFormat:@"http://cam.ppcam.tv/camera_image/2330000010/alarm.log"];
NSData *date = [NSData dataWithContentsOfURL:[NSURL URLWithString:fileURL]];
NSString* content = [[NSString alloc] initWithData:date encoding:NSASCIIStringEncoding];
//当子线程处理完成在主线程中处理
dispatch_sync(dispatch_get_main_queue(), ^{
m_labText.numberOfLines = 0;
m_labText.text = content;
self.m_strDataSource = content;
});
});
//延迟0.5秒执行
[self performSelector:@selector(clickloginBtn:) withObject:nil afterDelay:0.5];
还有很多,delegate的函数,用到在做补充