使用线程时如何解决错误?

Cha*_*iya 8 iphone xcode ios4 ios

我在使用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;




}
Run Code Online (Sandbox Code Playgroud)

这里的"DownloadAndParseUnderground"是从rss feed中下载数据的方法

-(void) Update_View{


    [self.tblView1 reloadData];
}
Run Code Online (Sandbox Code Playgroud)

当调用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;

    }
Run Code Online (Sandbox Code Playgroud)

AJP*_*tel 0

好的,请正确解释为什么在解析方法中需要线程?在您的代码中,您在线程中正确使用表重新加载方法......

因为

你不能把任何与你的视图相关的东西放在线程中......

你只能在其中放入诸如解析之类的后台进程...如果你想在解析后重新加载表,你可以在代码中使用一些标志值,并在解析后加载表