I am trying to use the new iOS 6 auto-layout feature in a custom UITableViewCell that was implemented programmatically. I added addConstraint calls, and it works correctly first - until I scroll. When I return to the camera after scrolling, the layout is broken. Destroyed, I mean that the fields between the fields are incorrect (too large, which significantly exceeds the cell size). I suppose this has something to do with the dequeueReusableCellWithIdentifier method, leaving me with a dirty cell, just like you need to reinitialize the fields inside the cells, but I can't do anything to persuade it to display correctly again. I tried calling [self.contentView updateConstraints] before returning the cell. I tried to destroy the constraints and recreate them. Not only does this not work, but if he tried layoutSubviews, it freezes in an infinite loop. Any ideas?
Here is the code for setting limits. It is located in initWithStyle: reuseIdentifier:
[self.completedLabel setTranslatesAutoresizingMaskIntoConstraints:NO]; [self.nextSetHeaderLabel setTranslatesAutoresizingMaskIntoConstraints:NO]; [self.nextSetDetailLabel setTranslatesAutoresizingMaskIntoConstraints:NO]; [self.youWillLearnHeaderLabel setTranslatesAutoresizingMaskIntoConstraints:NO]; [self.youWillLearnDetailLabel setTranslatesAutoresizingMaskIntoConstraints:NO]; [self.contentView removeConstraints:[self.contentView constraints]]; NSDictionary *views = NSDictionaryOfVariableBindings(_completedLabel, _nextSetHeaderLabel, _nextSetDetailLabel, _youWillLearnHeaderLabel, _youWillLearnDetailLabel); [self.contentView addConstraints: [NSLayoutConstraint constraintsWithVisualFormat:@"H:|-5-[_completedLabel]-5-|" options:0 metrics:nil views:views]]; [self.contentView addConstraints: [NSLayoutConstraint constraintsWithVisualFormat:@"H:|-5-[_nextSetHeaderLabel]-5-|" options:0 metrics:nil views:views]]; [self.contentView addConstraints: [NSLayoutConstraint constraintsWithVisualFormat:@"H:|-5-[_nextSetDetailLabel]-5-|" options:0 metrics:nil views:views]]; [self.contentView addConstraints: [NSLayoutConstraint constraintsWithVisualFormat:@"H:|-5-[_youWillLearnHeaderLabel]-5-|" options:0 metrics:nil views:views]]; [self.contentView addConstraints: [NSLayoutConstraint constraintsWithVisualFormat:@"H:|-5-[_youWillLearnDetailLabel]-4-|" options:0 metrics:nil views:views]]; [self.contentView addConstraints: [NSLayoutConstraint constraintsWithVisualFormat:@"V:|-5-[_completedLabel]-12-[_nextSetHeaderLabel]-0-[_nextSetDetailLabel]-12-[_youWillLearnHeaderLabel]-0-[_youWillLearnDetailLabel(>=20)]-1-|" options:0 metrics:nil views:views]];
source share