Note that there are some explanatory texts on larger screens.

plurals
  1. POAuto layout of custom programmatic UITableViewCell fails upon scrolling
    primarykey
    data
    text
    <p>I'm trying to use the new auto layout capability of iOS 6 on a custom UITableViewCell which has been implemented programmatically. I added the addConstraint calls, and it works properly at first-- until I scroll. When I come back to the cell after scrolling the layout is trashed. By trashed I mean the margins between fields are all wrong (too large, well beyond the size of the cell). I'm speculating this has something to do with the dequeueReusableCellWithIdentifier method leaving me with a "dirty" cell, the same way you find yourself needing to reinitialize fields within cells, but I can't seem to do anything to coax it to render properly again. I've tried calling [self.contentView updateConstraints] before returning the cell. I've tried destroying the constraints and recreating them. Not only does it not work, but if it's attempted in layoutSubviews it freezes in an endless loop of some kind. Any ideas?</p> <p>Here's the code to establish the constraints. It's located in initWithStyle:reuseIdentifier:</p> <pre><code>[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(&gt;=20)]-1-|" options:0 metrics:nil views:views]]; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload