iOS: Unable to simultaneously satisfy constraints when in segue

我的未来我决定 提交于 2019-12-24 11:23:13

问题


I am trying to make a segue from a tableview into a UIViewController, but I'm getting a curious error. The error occurs even if the target view is completely empty, just added to the storyboard. My thought is some element of sending view is triggering the error, but I am confused why this is only showing when exiting that TableViewController, not when loading it initially.

This is the stack trace form the error:

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.
2014-10-14 00:52:23.472 Phood[54950:70b] 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:0x9d56270 H:[PHStarsView:0x9d9c4a0(70)]>",
    "<NSLayoutConstraint:0xf544940 H:|-(20)-[PHStarsView:0x9d9c4a0]   (Names: '|':UITableViewCellContentView:0x9fcd710 )>",
    "<NSLayoutConstraint:0xf543d90 H:[PHStarsView:0x9d9c4a0]-(80)-|   (Names: '|':UITableViewCellContentView:0x9fcd710 )>",
    "<NSAutoresizingMaskLayoutConstraint:0x9d774e0 h=--& v=--& H:[UITableViewCellContentView:0x9fcd710(320)]>"
)

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x9d56270 H:[PHStarsView:0x9d9c4a0(70)]>

回答1:


I ran into the same problem with a custom UITableViewCell nib. Something about deallocating the cell breaks constraints.

Try adding

- (CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return UITableViewAutomaticDimension;
}



回答2:


You are adding constraints to your views and yet you have translatesAutoresizingMaskIntoConstraints set to YES on your cell's contentView. Set that to NO--you obviously want to be in control of your constraints and not use iOS's defaults.



来源:https://stackoverflow.com/questions/26355770/ios-unable-to-simultaneously-satisfy-constraints-when-in-segue

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!