CustomTableCellView的-layoutSubviews实现需要调用super,NSInternalInconsistencyException

HDd*_*per 8 iphone uitableview ios ios6

在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:
Run Code Online (Sandbox Code Playgroud)

在iOS 5模拟器中运行时

*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'The NIB data is invalid.'
*** First throw call stack:
Run Code Online (Sandbox Code Playgroud)

温度修复:

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

rai*_*ade 5

layoutSubviews needs to call super
Run Code Online (Sandbox Code Playgroud)

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

[theContainerView setTranslatesAutoresizingMaskIntoConstraints:NO]; 
Run Code Online (Sandbox Code Playgroud)

对于容器和子视图


Ant*_*ton 1

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

假设您使用 Storyboard,如果您想使用 AutoLayout 但仍保留与 6.0 之前的 iOS 版本的兼容性,则需要创建两个目标:一个用于 iOS 6,另一个用于 iOS 5(或更早版本)。对于每个故事板,设置一个单独的故事板,其中一个启用了自动布局(对于 iOS 6),另一个则不启用自动布局(对于 iOS 5)。

以下是 StackOverflow 线程,介绍了自动布局和与 iOS 5 的向后兼容性的最佳实践: 在 iOS 6 中启用自动布局,同时保持与 iOS 5 的向后兼容

根据我的经验,如果您想要向后兼容,那么使用 AutoLayout 是不值得的。如果您使用故事板,则需要同步 2 个目标和 2 个故事板,维护工作会很麻烦。如果您不使用故事板,则需要针对 iOS 5 和 iOS 6 的单独代码,这将需要更长的时间来测试和更新。