【问题标题】:UIWebView as part of a UITableViewCell: leading to crash because of a thread lockUIWebView 作为 UITableViewCell 的一部分:由于线程锁导致崩溃
【发布时间】:2010-06-22 20:46:27
【问题描述】:

我正在尝试添加 UIWebView 作为 UITableViewCell 的子视图,以便显示一些使用 MIMEType 'application/xhtml+xml' 格式化的数据。 即使只是按照以下代码中的描述初始化 UIWebView 也会导致应用程序崩溃!

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {    
NSLog(@"cellForRowAtIndexPath: '%d' in section '%d'", indexPath.section, indexPath.row);

static NSString *CellIdentifier = @"Cell";

UITableViewCell *cell = (UITableViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}

UIWebView * webView = [[UIWebView alloc]initWithFrame:cell.frame];

return cell;

}

我收到了这条消息:

bool _WebTryThreadLock(bool), 0x10a7f50: 试图从主线程或web线程以外的线程获取web lock。这可能是从辅助线程调用 UIKit 的结果。现在崩溃了……

我不知道我哪里做错了!

感谢您的帮助

杰拉德

【问题讨论】:

    标签: iphone uitableview uiwebview multithreading locking


    【解决方案1】:

    错误信息告诉你发生了什么:你可能不在主线程上?您应该只从主线程访问 UIKit。

    此外,cell.frame 很可能不是您想要的。尝试使用CGRectMake(...) 设置固定大小。不要忘记添加它。 :-)

    【讨论】:

    • 哇!你拯救了我的夜晚!仅阅读消息对我来说是不够的,您推动我在代码中向前看。我在一个新线程中调用 reloadData 方法,也就是不是主线程!非常感谢来自法国 Gerald 的 Eiko 问候
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-10-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-08-12
    • 2018-09-03
    • 2012-02-01
    相关资源
    最近更新 更多