首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >根据自动调整掩码,UITableViewCellContentView宽度始终为零(仅在iOS 7上)

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

Stack Overflow用户
提问于 2014-11-21 08:39:45
回答 2查看 3.1K关注 0票数 2

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

代码语言:javascript
复制
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.

现在我们关注这一部分:

代码语言:javascript
复制
"<NSAutoresizingMaskLayoutConstraint:0x7a706970 h=--& v=--& H:[UITableViewCellContentView:0x7a707ba0(0)]>"

它说,根据自动调整掩码,UITableViewCellContentView的宽度为零。但是,相同的代码以前在另一个视图控制器上工作。在视图控制器中,弹出器应该独立于我的设置。我试图在另一个项目中复制这种行为,但我做不到。这也只出现在iOS 7上。在iOS 8上,一切都很好。我也试图远离自动布局,然后内容就会显示出来(但不是以我想要的方式)。我唯一能想到的办法就是回到春天去.如果您想要的话,我可以用C#提供我的代码,但为了使问题更易读,我忽略了它。

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

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2014-11-21 11:11:00

在搜索了一天的原因后,这是一个人可能会犯的默认错误。因为我以前有控制器,而不是在弹出程序中,所以下面的代码行仍然存在:

代码语言:javascript
复制
myViewControllerInPopup.View.TranslatesAutoresizingMaskIntoConstraints = false;

我在视图控制器上找到了这个,它实例化了弹出器。删除这一行,一切都按预期进行。

票数 5
EN

Stack Overflow用户

发布于 2021-08-26 07:26:20

受测试启发的助手检查器

代码语言:javascript
复制
extension UIView {
  func assertDoesNotTranslateAutoresizingMaskIntoConstraints(recurse: Bool = false) {
    if translatesAutoresizingMaskIntoConstraints {
      assertionFailure()
    }
    for view in subviews {
      if recurse {
        view.assertDoesNotTranslateAutoresizingMaskIntoConstraints(recurse: true)
      }
      if view.translatesAutoresizingMaskIntoConstraints {
        assertionFailure()
      }
    }
  }

}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/27057181

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档