无法更改tableview框架

时间:2016-08-28 22:07:48

标签: ios uitableview autolayout uicollectionview

我只想在viewwillappear中使用easyPeasy更改tableview框架以进行自动布局。

我在一个viewcontroller中有collectionview和tableview。我正在使用它们。但是在第一次打开时我隐藏了collectionview并试图将tableview y指向0。

override func viewWillAppear(animated: Bool) {
        super.viewWillAppear(true)
        self.collectionView.hidden = true
        self.tableView <- [
            Top(0).to((self.navigationController?.navigationBar)!, .Bottom)
        ]
    }

它给了我这个错误。

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. 
(
    "<NSLayoutConstraint:0x14c06f370 UIImageView:0x14c1c2d30.width == 40>",
    "<NSLayoutConstraint:0x14c1e5ff0 UIImageView:0x14c1c2d30.width == 22>"
)

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x14c06f370 UIImageView:0x14c1c2d30.width == 40>

Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful.
nil
2016-08-29 01:06:37.034 Bons[985:280487] 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. 
(
    "<NSLayoutConstraint:0x14c0e29d0 UIImageView:0x14c1e9ee0.width == 40>",
    "<NSLayoutConstraint:0x14c1e7f00 UIImageView:0x14c1e9ee0.width == 22>"
)

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x14c0e29d0 UIImageView:0x14c1e9ee0.width == 40>

Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful.
nil
2016-08-29 01:06:37.044 Bons[985:280487] 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. 
(
    "<NSLayoutConstraint:0x14c0f5c50 UIImageView:0x14c0f4a10.width == 40>",
    "<NSLayoutConstraint:0x14c1e7fc0 UIImageView:0x14c0f4a10.width == 22>"
)

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x14c0f5c50 UIImageView:0x14c0f4a10.width == 40>

Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful.
nil
2016-08-29 01:06:37.053 Bons[985:280487] 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. 
(
    "<NSLayoutConstraint:0x14c0f5930 UILabel:0x14c0f5020.centerY == UITableViewCellContentView:0x14c0f3c60.centerY>",
    "<NSLayoutConstraint:0x14c0f59d0 UIImageView:0x14c0f4a10.top == UIImageView:0x14c0f5600.top + 5>",
    "<NSLayoutConstraint:0x14c0f5a70 UIImageView:0x14c0f4a10.centerY == UILabel:0x14c0f5020.centerY>",
    "<NSLayoutConstraint:0x14c0f5b10 UITableViewCellContentView:0x14c0f3c60.bottomMargin == UIImageView:0x14c0f5600.bottom - 1>",
    "<NSLayoutConstraint:0x14c0f5bb0 UIImageView:0x14c0f5600.height == 38>",
    "<NSLayoutConstraint:0x14c1f5330 UIImageView:0x14c0f4a10.height == 22>",
    "<NSLayoutConstraint:0x14c1f4cc0 UITableViewCellContentView:0x14c0f3c60.height == 54>"
)

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x14c0f5bb0 UIImageView:0x14c0f5600.height == 38>

Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful.
2016-08-29 01:06:37.062 Bons[985:280487] 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. 
(
    "<NSLayoutConstraint:0x14c0efad0 UILabel:0x14c0f07b0.centerY == UITableViewCellContentView:0x14c1e85d0.centerY>",
    "<NSLayoutConstraint:0x14c0e25a0 UIImageView:0x14c1e9ee0.top == UIImageView:0x14c0ef890.top + 5>",
    "<NSLayoutConstraint:0x14c0e2640 UIImageView:0x14c1e9ee0.centerY == UILabel:0x14c0f07b0.centerY>",
    "<NSLayoutConstraint:0x14c0e2890 UITableViewCellContentView:0x14c1e85d0.bottomMargin == UIImageView:0x14c0ef890.bottom - 1>",
    "<NSLayoutConstraint:0x14c0e2930 UIImageView:0x14c0ef890.height == 38>",
    "<NSLayoutConstraint:0x14c0f1c90 UIImageView:0x14c1e9ee0.height == 22>",
    "<NSLayoutConstraint:0x14c1f87a0 UITableViewCellContentView:0x14c1e85d0.height == 54>"
)

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x14c0e2930 UIImageView:0x14c0ef890.height == 38>

Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful.
2016-08-29 01:06:37.070 Bons[985:280487] 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. 
(
    "<NSLayoutConstraint:0x14c089ce0 UILabel:0x14c0c8050.centerY == UITableViewCellContentView:0x14c06e390.centerY>",
    "<NSLayoutConstraint:0x14c089d80 UIImageView:0x14c1c2d30.top == UIImageView:0x14c071f20.top + 5>",
    "<NSLayoutConstraint:0x14c089e20 UIImageView:0x14c1c2d30.centerY == UILabel:0x14c0c8050.centerY>",
    "<NSLayoutConstraint:0x14c06f230 UITableViewCellContentView:0x14c06e390.bottomMargin == UIImageView:0x14c071f20.bottom - 1>",
    "<NSLayoutConstraint:0x14c06f2d0 UIImageView:0x14c071f20.height == 38>",
    "<NSLayoutConstraint:0x14c1e5560 UIImageView:0x14c1c2d30.height == 22>",
    "<NSLayoutConstraint:0x14c211d80 UITableViewCellContentView:0x14c06e390.height == 54>"
)

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x14c06f2d0 UIImageView:0x14c071f20.height == 38>

1 个答案:

答案 0 :(得分:1)

问题是您正在尝试建立不包含在同一视图中的项目之间的关系。相反,你可以:

override func viewWillAppear(animated: Bool) {
    super.viewWillAppear(true)
    self.collectionView.hidden = true
    self.tableView <- [
        Top(0).to(self.topLayoutGuide))
    ]
}