Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IOS Custom Table Cell does not Automatically Resize Width for Orientation Change

Have a custom table cell with it's own .XIB and .h and .m. Nothing too fancy. When the device rotates, the cell width does not change. The tables cell for index path is called, but width is not changes (say from portrait to landscape). What would be preventing this?

Don't want to hand set the frame size.

Will post code if need to, but maybe we can answer with out code on this one.

Even if starting the app in landscape also does not set the larger width for the cell.

[Addition]

Also does not work with non-custom cells.

self.tableViewSelection.autoresizesSubviews = true;
self.tableViewSelection.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
self.view.autoresizesSubviews = true;

XIB for the table has the resizing seemed to be setup correctly (non-IOS6 Support).

like image 658
ort11 Avatar asked May 13 '13 17:05

ort11


3 Answers

If you are overriding the layoutSubviews or another method, don't forget to call it's super:

override func layoutSubviews() {
    //...

    super.layoutSubviews()
}

Not doing this will result in the problem you are facing.

like image 58
Bruno Lemos Avatar answered Nov 15 '22 18:11

Bruno Lemos


The cell will automatically be the same width as the table view. So what is not resizing might be the table view. You need to give it appropriate constraints (if using Autolayout, the default in iOS 6) or autoresizing mask (otherwise) so that it will resize in response to the top-level view resizing to compensate for device rotation.

like image 33
matt Avatar answered Nov 15 '22 16:11

matt


I also faced this same issue while autoresizing custom cells on rotating. After fighting I got the solution as authorize cell.contentView, because I am adding my views as subview into cell.contentview.

I used following code and my code works fine :)

cell.contentView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin;
like image 32
Kirti Nikam Avatar answered Nov 15 '22 16:11

Kirti Nikam