iphone – 如何在使用线程时解决错误?
发布时间:2020-12-14 20:00:06 所属栏目:百科 来源:网络整理
导读:使用NSThread时,我在控制台中有以下错误消息 “试图从主线程或网络线程以外的线程获取Web锁.这可能是从辅助线程调用UIKit的结果.现在崩溃……” 我在这里提交了示例代码 - (void)viewDidLoad { appDeleg = (NewAshley_MedisonAppDelegate *)[[UIApplication
使用NSThread时,我在控制台中有以下错误消息
“试图从主线程或网络线程以外的线程获取Web锁.这可能是从辅助线程调用UIKit的结果.现在崩溃……” 我在这里提交了示例代码 - (void)viewDidLoad { appDeleg = (NewAshley_MedisonAppDelegate *)[[UIApplication sharedApplication] delegate]; [[self tblView1] setRowHeight:80.0]; [super viewDidLoad]; self.title = @"Under Ground"; [UIApplication sharedApplication].networkActivityIndicatorVisible = YES; [NSThread detachNewThreadSelector:@selector(CallParser) toTarget:self withObject:nil]; } -(void)CallParser { Parsing *parsing = [[Parsing alloc] init]; [parsing DownloadAndParseUnderground]; [parsing release]; [self Update_View]; //[myIndicator stopAnimating]; [UIApplication sharedApplication].networkActivityIndicatorVisible = NO; } 这里的“DownloadAndParseUnderground”是从rss feed中下载数据的方法 -(void) Update_View{ [self.tblView1 reloadData]; } 当调用Update_View方法时,tableView重载数据并在cellForRowAtIndexPath中创建错误而不显示自定义单元格 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"Cell"; CustomTableviewCell *cell = (CustomTableviewCell *) [tblView1 dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) { [[NSBundle mainBundle] loadNibNamed:@"customCell" owner:self options:nil]; cell = objCustCell; objCustCell = nil; } 解决方法
好请解释正确为什么在解析方法中需要线程?在你的代码中你在正确的线程中使用表重载方法….
因为 你不能把任何与你的VIEW相关的东西放在线程中…… 你只能把后台进程像解析一样…如果你想在解析之后重新加载表你可以在你的代码中使用一些标志值并在解析你的加载表之后 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |