【问题标题】:UITableViewCell throwing exceptionUITableViewCell 抛出异常
【发布时间】:2014-11-09 08:04:52
【问题描述】:

我正在将一个项目更新到 iOS 8,并且我的 UITableViewCell 实现之一遇到了这个问题。目前在模拟器上而不是设备上,它设置为“iPhone 6”。

*** Assertion failure in -[UITableViewCell _setHostsLayoutEngine:], /SourceCache/UIKit_Sim/UIKit-3318/NSLayoutConstraint_UIKitAdditions.m:2754
2014-09-15 10:43:52.890 BasketballStatTracker[10662:304085] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Must translate autoresizing mask into constraints to have _setHostsLayoutEngine:YES.'

奇怪的是,我在所有其他 UITableView 中都使用了这个自定义 UITableViewCell 子类,并且它在没有任何断言的情况下运行良好。

这里是 cellForRowAtIndexPath: 实现。

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

这是堆栈跟踪

0   CoreFoundation                      0x000000010844e3f5 __exceptionPreprocess + 165
1   libobjc.A.dylib                     0x00000001080e7bb7 objc_exception_throw + 45
2   CoreFoundation                      0x000000010844e25a +[NSException raise:format:arguments:] + 106
3   Foundation                          0x0000000107ac228f -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 195
4   UIKit                               0x0000000106de2e1c -[UIView(AdditionalLayoutSupport) _setHostsLayoutEngine:] + 188
5   UIKit                               0x00000001069e7d92 -[UITableViewCell _setupTableViewCellCommon] + 333
6   UIKit                               0x00000001069e84d7 -[UITableViewCell initWithCoder:] + 109
7   UIKit                               0x0000000106b8a996 UINibDecoderDecodeObjectForValue + 705

有什么想法吗?

【问题讨论】:

    标签: ios objective-c uitableview ios8 xib


    【解决方案1】:

    我找到了一个错误的 UITableViewCell,它位于有问题的 .xib 的视图层次结构中。删除它解决了问题。

    【讨论】:

    • 如果我没记错的话,我的 .xib 中有一个我不知道的 UITableViewCell UI 元素。您使用的是故事板还是 xib?
    • 我正在使用故事板
    • 那么答案是什么?我仍然坚持这个愚蠢的错误。有什么线索吗?
    • Kaveh Vejdani 您的 UI 结构是什么?你在使用自动布局吗?你有可以链接的线程吗?如果是这样,我会看看它是否与我遇到的问题相似。
    • 取消选中自动布局正在为我修复错误......但问题是我真的很想使用自动布局:/对我来说唯一有问题的页面是我使用的页面UIView 中的表格视图单元格,这可能会导致问题(如此处所述:stackoverflow.com/questions/24217195/…
    猜你喜欢
    • 2013-05-24
    • 2011-05-30
    • 1970-01-01
    • 2011-02-25
    • 2012-01-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多