Created a UITableViewController table. It creates a certain number of cells. They are filled from the array. Custom cells. Every cell has a UIView. In the tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) function tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) I add a constraint to this UIView that sets the height. If picsCount is 0, then a constraint is created with a height of 0, and if it is greater than zero, then with its own special height.
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { let cell = tableView.dequeueReusableCellWithIdentifier("postCell", forIndexPath: indexPath) as! CustomPostCellTableViewCell let picsCount = allposts[indexPath.row].pic.count print(picsCount) if picsCount > 0 { let heightConstraint = NSLayoutConstraint(item: cell.viewVW, attribute: .Height, relatedBy: .Equal, toItem: nil, attribute: .NotAnAttribute, multiplier: 1.0, constant: 100) cell.viewVW.addConstraint(heightConstraint) } else if picsCount == 0 { let heightConstraint = NSLayoutConstraint(item: cell.viewVW, attribute: .Height, relatedBy: .Equal, toItem: nil, attribute: .NotAnAttribute, multiplier: 1.0, constant: 0) cell.viewVW.addConstraint(heightConstraint) } return cell } When I start to scroll through this list, it turns out that some cells have zero height, others have not zero. And the first cells should have gone zero, but this is not observed, they are in discord.
And also in debug it gives out this:
2016-09-01 23:37:18.723 FriendDime[10039:2879999] 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:0x7a78c9d0 V:[UIView:0x7a7a2890(100)]>", "<NSLayoutConstraint:0x7a69c730 V:[UIView:0x7a7a2890(0)]>" ) Will attempt to recover by breaking constraint <NSLayoutConstraint:0x7a78c9d0 V:[UIView:0x7a7a2890(100)]> 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 assume that the cell is reused and the constraint is being added to it again. And it turns out that in some cells it turns out two constraints, one with a zero height, and the second with a height of 100.
And I also want to add to this UIView dynamically images, the number of which will be different in each cell. And what does this work with pictures, too, will be such problems?
Explain how to deal with this?