【问题标题】:CustomTableCellView's implementation of -layoutSubviews needs to call super , NSInternalInconsistencyExceptionCustomTableCellView 的 -layoutSubviews 实现需要调用 super , NSInternalInconsistencyException
【发布时间】:2012-11-17 15:00:13
【问题描述】:

在 tableView xib 的自定义单元格中使用 autoLayout 时,我收到以下错误。

在 iOS 6 模拟器中运行时 CustomCells的-layoutSubviews的实现需要调用super

Assertion failure in 

-[CustomCells layoutSublayersOfLayer:], /SourceCache/UIKit_Sim/UIKit-2372/UIView
     *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Auto Layout still required after executing -layoutSubviews. CustomCells's implementation of -layoutSubviews needs to call super.'
    *** First throw call stack:

在 iOS 5 模拟器中运行时

*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'The NIB data is invalid.'
*** First throw call stack:

临时修复:

如果在自定义单元格中禁用自动布局,它工作正常。 但在这种情况下,方向处理并不好。请帮忙。

【问题讨论】:

  • 当您在该视图上调用 addSubview 调用 layoutSubviews 时,例如:[cell addSubview:contentView]; [单元格布局子视图];
  • 与工作解决方案类似的问题:stackoverflow.com/questions/12610783/…

标签: iphone ios uitableview ios6


【解决方案1】:
layoutSubviews needs to call super

可以通过将所有内容放在容器视图中的自定义 tableview 单元格中来解决 iOS6 问题。即创建一个新视图来填充单元格,然后在其中放置控件等。还要确保你设置:

[theContainerView setTranslatesAutoresizingMaskIntoConstraints:NO]; 

对于容器和子视图

【讨论】:

  • 你在哪里设置 translatesautorisizingMaskIntoConstraints?在 initWithStyle 方法或 ViewDidLoad 或其他地方?
【解决方案2】:

iOS 5.1 及更早的版本与 AutoLayout 不兼容。它仅适用于 iOS 6.0+。

假设您正在使用情节提要,如果您想使用 AutoLayout 但仍保持与 6.0 之前的 iOS 版本的兼容性,则需要创建两个目标:一个用于 iOS 6,另一个用于 iOS 5(或更早版本)。对于每一个,设置一个单独的故事板,一个启用 AutoLayout(对于 iOS 6),一个不启用(对于 iOS 5)。

这里有一个 StackOverflow 线程,了解 AutoLayout 和向后兼容 iOS 5 的最佳实践:Enabling auto layout in iOS 6 while remaining backwards compatible with iOS 5

根据我的经验,如果您想要向后兼容,那么使用 AutoLayout 是不值得的。如果您使用情节提要,要同步 2 个目标和 2 个情节提要是一件令人头疼的事情。如果您不使用情节提要,则需要为 iOS 5 和 iOS 6 单独编写代码,这将需要更长的时间来测试和更新。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-11-10
    • 1970-01-01
    • 2015-04-22
    • 1970-01-01
    • 2015-09-29
    • 1970-01-01
    • 2023-04-04
    • 1970-01-01
    相关资源
    最近更新 更多