根据自动调整大小掩码,UITableViewCellContentView 宽度始终为零(仅在 iOS 7 上)

标签 uitableview ios7 autolayout uipopovercontroller autoresizingmask

我正在使用动态单元格高度的自动布局方法,如 Using Auto Layout in UITableView for dynamic cell layouts & variable row heights 中所述。 。到目前为止这有效。现在,我在 UIPopoverController 中展示我的 UITableView,它也可以工作。现在到有趣的部分:我从不同的 View Controller 呈现这个弹出窗口。在第一个 View Controller 上,一切都按预期工作。如果我切换到第二个 View Controller (它也提供此弹出窗口),则弹出窗口完全是空的(即使没有分隔线!)并且我收到以下错误:

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 的宽度为零。但相同的代码之前可以在另一个 View Controller 上运行。并且弹出窗口应该独立于我在 View Controller 中的设置。我尝试在另一个项目中复制该行为,但我做不到。这也只出现在 iOS 7 上。在 iOS 8 上一切正常。我还尝试摆脱自动布局,然后显示内容(但不是以我想要的方式)。我能想到的唯一选择是回到 spring 和 struts ...如果您愿意,我可以提供我的 C# 代码,但我将其保留下来以使问题更具可读性。

这可能是什么原因?有人经历过这样的事情吗?

最佳答案

在寻找了一天的原因后,这​​是人们可能犯的默认错误。因为我之前有 Controller 而不是在弹出窗口中,所以以下代码行仍然存在:

myViewControllerInPopup.View.TranslatesAutoresizingMaskIntoConstraints = false;

我在实例化弹出窗口的 View Controller 上有这个。删除此行,一切都会按预期工作。

关于根据自动调整大小掩码,UITableViewCellContentView 宽度始终为零(仅在 iOS 7 上),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27057181/

相关文章:

iphone - 如何在 iOS 7 中以编程方式正确关闭 UIAlertView?

ios - 不同iOS设备尺寸编程方法

ios - UITableViewCell 删除内容

objective-c - UITableView.ScrollToTop - 改变它认为的 "top"

JavaScriptCore + Socket.IO

iOS - 使用用户名和密码登录 Twitter

swift - 如何以编程方式对我在容器 View 中调用的 ViewController 施加约束?

Xcode 根据屏幕方向更改约束

iphone - UItableViewGrouped中出现多次的文本字段

swift - Rxswift 的 UITableView 中的 UISearchBar