1

I have created a table view with prototype cells in a Storyboard with the "Use Autolayout" unchecked in Xcode 5.

The cells are UITableViewCell subclasses, mainly to add IBOutlets and no code inside. The result is a messed layout. I tried changing the Autoresizing masks with no luck. Also tried this.

If I however implement an empty layoutSubviews it shows ok. Any idea of what's going on? Is auto layout still enabled despite unchecking it?

Edit:

More details...

@interface SettingDefaultTableViewCell : UITableViewCell

@property (nonatomic, weak) IBOutlet UILabel *label;
@property (nonatomic, weak) IBOutlet UIImageView *imageView;
@property (nonatomic, weak) IBOutlet UIView *backgroundView;

@end

@implementation SettingDefaultTableViewCell

- (void)layoutSubviews
{
    // Emtpy implementation to fix weird layout bug
}

@end

Storyboard with Autolayout disabled:

enter image description here

Result when layoutSubviews fix above is not used:

enter image description here

Edit 2:

  • The cell is set to not autoresize subviews.
  • While the above should be enough to prevent subviews from getting auto-adjusted, also all autoresizing masks are set to flexible right and bottom margin only.
  • Only the > mark is set to flexible left margin. No flexible width or height.
Community
  • 1
  • 1
Rivera
  • 10,792
  • 3
  • 58
  • 102
  • This question is kind of pointless. I've never had any issue with UITableViewCell subclasses and layouts, so there's no way for me to guess at what your problem is. You've included very little detail on what you've done, so it's impossible for me to recreate the problem. – nhgrif Feb 18 '14 at 02:15
  • There are not much details because as I said the subclass code is empty, so no point to post that. If you read the questions in the links you'll see that UITableView cell has many quirks in different iOS versions. In my case autoLayout seems to be active even though it was uncheck in IB. – Rivera Feb 18 '14 at 08:38
  • If you think the issue is related to the version of iOS, why haven't you bothered mentioning it? You don't really explain how the view is messed up. You don't provide a picture of how the cell looks in storyboard versus how it looks when running. I mean, there's nothing here. Nothing to recreate the issue. – nhgrif Feb 18 '14 at 12:25
  • Added images, but basically it was all described already. – Rivera Feb 19 '14 at 02:40
  • The only problem I can see is the > is on the left rather than right. Is that correct? – nhgrif Feb 19 '14 at 02:43
  • If you're not using auto-layout, I'd guess an issue with your springs and struts. – Aaron Brager Feb 19 '14 at 02:44
  • Added more details concerning the autoresizing settings. The label is offset to the left and the ">" is completely out of place. So all two elements of this custom cell have a messed layout unless I override `layoutSubviews`. – Rivera Feb 19 '14 at 03:03
  • Is the cell's *content view* set to not autoresize subviews? Or only the cell itself? – Aaron Brager Feb 19 '14 at 03:20
  • Both. Anyway I would expect only the cell's settings to matter as it is the cell's `layoutSubviews` that fixes it. – Rivera Feb 19 '14 at 04:36

1 Answers1

0

The cell is getting modified by the undocumented UITableViewCell's layoutSubviews:

  • Despite set not no autoresize subviews, the default implementation changes the backgroundView frame.
  • It also moves imageView (the ">") to the left despite being configured as a Custom Style cell.

Thus avoiding executing super's layoutSubviews fixes it.

Rivera
  • 10,792
  • 3
  • 58
  • 102