我正在使用动态单元格高度的自动布局方法,如Using Auto Layout in UITableView for dynamic cell layouts & variable row heights中所描述的。到目前为止这是可行的。现在,我在UIPopoverController中展示我的UIPopoverController,它也能工作。现在来看有趣的部分:我从不同的视图控制器中呈现这个弹出窗口。在第一个视图控制器上,一切都按预期工作。如果我切换到第二个视图控制器(它也提供了这个弹出窗口),则弹出完全是空的(即使没有分隔线!)我得到了以下错误:
Unable to simultaneously satisfy constraints.
Probably at least one of the constraints in the following list is one you don't want. Try this: (1) look at each constraint and try to figure out which you don't expect; (2) find the code that added the unwanted constraint or constraints and fix it. (Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints)
(
"<NSLayoutConstraint:0x7a706fa0 H:|-(8)-[UILabel:0x7a707760] (Names: '|':UITableViewCellContentView:0x7a707ba0 )>",
"<NSLayoutConstraint:0x7a707060 H:[UILabel:0x7a707760]-(8)-| (Names: '|':UITableViewCellContentView:0x7a707ba0 )>",
"<NSAutoresizingMaskLayoutConstraint:0x7a706970 h=--& v=--& H:[UITableViewCellContentView:0x7a707ba0(0)]>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x7a707060 H:[UILabel:0x7a707760]-(8)-| (Names: '|':UITableViewCellContentView:0x7a707ba0 )>
Break on objc_exception_throw to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful.现在我们关注这一部分:
"<NSAutoresizingMaskLayoutConstraint:0x7a706970 h=--& v=--& H:[UITableViewCellContentView:0x7a707ba0(0)]>"它说,根据自动调整掩码,UITableViewCellContentView的宽度为零。但是,相同的代码以前在另一个视图控制器上工作。在视图控制器中,弹出器应该独立于我的设置。我试图在另一个项目中复制这种行为,但我做不到。这也只出现在iOS 7上。在iOS 8上,一切都很好。我也试图远离自动布局,然后内容就会显示出来(但不是以我想要的方式)。我唯一能想到的办法就是回到春天去.如果您想要的话,我可以用C#提供我的代码,但为了使问题更易读,我忽略了它。
这是什么原因?有人经历过这样的事情吗?
发布于 2014-11-21 11:11:00
在搜索了一天的原因后,这是一个人可能会犯的默认错误。因为我以前有控制器,而不是在弹出程序中,所以下面的代码行仍然存在:
myViewControllerInPopup.View.TranslatesAutoresizingMaskIntoConstraints = false;我在视图控制器上找到了这个,它实例化了弹出器。删除这一行,一切都按预期进行。
发布于 2021-08-26 07:26:20
受测试启发的助手检查器
extension UIView {
func assertDoesNotTranslateAutoresizingMaskIntoConstraints(recurse: Bool = false) {
if translatesAutoresizingMaskIntoConstraints {
assertionFailure()
}
for view in subviews {
if recurse {
view.assertDoesNotTranslateAutoresizingMaskIntoConstraints(recurse: true)
}
if view.translatesAutoresizingMaskIntoConstraints {
assertionFailure()
}
}
}
}https://stackoverflow.com/questions/27057181
复制相似问题