UITableView loaded from NIB with autoLayout has wrong constraints

Originator:darxmac
Number:rdar://13179719 Date Originated:08-Feb-2013 01:46 PM
Status:Open Resolved:
Product:iPhone SDK Product Version:6.1
Classification:UI/Usability Reproducible:yes
 
ummary:

When creating a UITableViewCell in a xib with AutoLayout on, all constraints created in IB are created for the view and not the contentView of the cell. This has the effect of mangling the layout when entering edit mode.

Steps to Reproduce:

Create UITableView xib, load with UInib

Expected Results:

Constraints should be created for the view not the contentView

Actual Results:

Constraints are created for the view

Notes:

After much saerching i found this post

<http://stackoverflow.com/a/13893146/1983506>

and the following snippet in the UITableViewCell's subclass 

- (void) awakeFromNib {
    
	[super awakeFromNib];

	for(NSLayoutConstraint *cellConstraint in self.constraints){
		[self removeConstraint:cellConstraint];
		id firstItem = cellConstraint.firstItem == self ? self.contentView : cellConstraint.firstItem;
		id seccondItem = cellConstraint.secondItem == self ? self.contentView : cellConstraint.secondItem;
		NSLayoutConstraint* contentViewConstraint =
		[NSLayoutConstraint constraintWithItem:firstItem
									 attribute:cellConstraint.firstAttribute
									 relatedBy:cellConstraint.relation
										toItem:seccondItem
									 attribute:cellConstraint.secondAttribute
									multiplier:cellConstraint.multiplier
									  constant:cellConstraint.constant];
		[self.contentView addConstraint:contentViewConstraint];
	}

}


fixes the problem

Comments


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!