WebTryThreadLock在loadNibNamed上崩溃

时间:2014-11-01 18:58:10

标签: ios uitableview uiwebview

我遇到了一直没有发生的崩溃,但经常发生这种事故。

UITableViewCell包含UIWebView

我得到了以下的崩溃:
bool _WebTryThreadLock(bool), 0x799b6480: Tried to obtain the web lock from a thread other than the main thread or the web thread. This may be a result of calling to UIKit from a secondary thread. Crashing now...

导致崩溃的代码:
(在viewcontroller上)

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 0)
    {
       ...
    }
    else //section 1 - regular "feed" cells
    {
        FeedDataItem *item = [currentItemArray objectAtIndex:indexPath.row] ;
        FeedItemCell *cell = [self prepareCell:item rowIndex:indexPath.row tableView:tableView];
        return cell;
    }
}

PrepareCell是一个服务函数,它服务于像这样的许多类,它以:

开头
- (FeedItemCell *)prepareCell:(FeedDataItem *)item rowIndex:(long)rowIndex tableView:(UITableView *)tableView
{
    FeedItemCell *cell = (FeedItemCell *)[tableView dequeueReusableCellWithIdentifier:@"FeedItemCell"];
    if (cell == nil)
    {
        NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"FeedItemCell" owner:self options:nil];  
        // <------- the crash is in the nib creation (the line above)  --------->
        cell = [nib objectAtIndex:0];
    }
    .....
}

我不明白 - 在非主线程上做了什么? 所有reloadData都在:

dispatch_async(dispatch_get_main_queue(), ^{
    [self.tableView reloadData];
});

(与堆栈线程无关 - 刚才提到没有涉及松散的reloadData)

0 个答案:

没有答案