简体   繁体   中英

NSLayoutConstrains error occurs when reorder the UITableViewCell

I set a simple cell in storyboard, 在此处输入图片说明

Thers's a imageview and a label, I set some constrains, it's imageView's leading ,top and bottom space to contentview, and the imageView's width and height, and the label's horizontal spacing to imageview and vertically center to imageview. 在此处输入图片说明 When I run the app, it shows correct, no error occurs. 在此处输入图片说明

The rightBarButtonItem is the system edit button. When I reorder the cell, constrain error occurs, I do not know how to fix it.

2015-11-11 23:08:05.681 HiPDA[10108:2305919] 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:0x7fce60ce6cf0 V:[UIImageView:0x7fce60cac370(40)]>",
"<NSLayoutConstraint:0x7fce60ce6f10 UITableViewCellContentView:0x7fce60ca0610.topMargin == UIImageView:0x7fce60cac370.top>",
"<NSLayoutConstraint:0x7fce60ce7020 UITableViewCellContentView:0x7fce60ca0610.bottomMargin == UIImageView:0x7fce60cac370.bottom - 0.5>",
"<NSLayoutConstraint:0x7fce60c03a70 'UIView-Encapsulated-Layout-Height' V:[UITableViewCellContentView:0x7fce60ca0610(56)]>"
)

Will attempt to recover by breaking constraint 

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.

I was confused, when it showed, scrlled and removed, no errors occur, but when I reordered the cell, constrain error occurs, I do not know how to fix it. Thank you.

I upload the project, you can download here download link

There's are two navigation controllers, change the init controller between them, when the tableviewcell contains only label no error occurs, but when the tableviewcell contains imageview error occurs when reorder cell.

Looking at your constraints the conflict is that

The imageview height is set to 40, it is pinned to the top and bottom of the cell, while the cell height is 56. how big do you want the imageview 40 or 56?

You can solve this by removing the top and bottom constraints and just do a center vertical to the cell constraint. ie ImageView.centerY = centerY

Here's modified constraints for your project on the image view 在此处输入图片说明

You gave imageView two Sets of constraints to determine it's height ,one is top&& bottom space, another is height.

When they conflicts with each other, you will get this alert.Change one of them to optional will fix the problem.

In you case ,You can change your imageView's height constraint from "=" to ">=" or lower height constraint's priority to 999.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM