【问题标题】:How to avoid background thread in iOS 9如何在 iOS 9 中避免后台线程
【发布时间】:2015-12-18 11:08:01
【问题描述】:

我正在开发应用程序,我使用自定义表格视图单元格来显示数据。当我的应用程序运行时,它会发出此警告。

This application is modifying the autolayout engine from a background thread, which can lead to engine corruption and weird crashes.  This will cause an exception in a future release

我已经添加了一些断点并查看了,这是什么时候来的。在这一点上(我调用客户表视图单元格的时间。)

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{

    AirportTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"identifier"];//in here it comes

    ac = [detailArray objectAtIndex:indexPath.row];
    cell.airportname.text = ac.airPort;


    return cell;

}

我试过了

dispatch_async(dispatch_get_main_queue(), ^{
    // code here
});

但我不知道如何正确使用它。有什么办法可以避免这种情况。希望你的回答。谢谢

【问题讨论】:

  • 那么,你在哪里进入后台线程?那会更有趣,因为您当前的狙击手实际上给出的线索为零,但您的AirportTableViewCell 中只是偷偷怀疑它正在发生,您还没有优雅地与我们分享。

标签: ios9 custom-cell background-thread


【解决方案1】:

cellForRowAtIndexPath: 不应从后台线程调用。您可能正在从后台线程调用 reloadData: 或类似的东西,这是非常不健康的。

【讨论】:

  • 是的,我用过[tableView reloadData],用它的最佳位置是什么。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2016-12-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-03-21
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多