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?
拥有自己的.XIB和.h和.m的自定义表格单元格。没什么太花哨的。当设备旋转时,单元格宽度不会改变。调用索引路径的表格单元格,但宽度不会更改(例如从纵向到横向)。什么会阻止这个?
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).
表的XIB似乎已正确设置调整大小(非IOS6支持)。
5 个解决方案
#1
7
If you are overriding the layoutSubviews
or another method, don't forget to call it's super:
如果您要覆盖layoutSubviews或其他方法,请不要忘记将其称为超级:
override func layoutSubviews() {
//...
super.layoutSubviews()
}
Not doing this will result in the problem you are facing.
不这样做会导致您遇到的问题。
#2
1
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.
单元格将自动与表格视图的宽度相同。所以没有调整大小的可能是表格视图。您需要为其提供适当的约束(如果使用Autolayout,iOS 6中的默认值)或自动调整遮罩(否则),以便调整大小以响应顶层视图的大小调整以补偿设备旋转。
#3
1
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.
在旋转时自动调整自定义单元格时,我也遇到了同样的问题。战斗结束后,我得到了解决方案作为authorize cell.contentView,因为我将我的视图作为子视图添加到cell.contentview中。
I used following code and my code works fine :)
我使用以下代码,我的代码工作正常:)
cell.contentView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin;
#4
1
For swift 2, it will be:
对于swift 2,它将是:
cell.contentView.autoresizingMask = [.FlexibleWidth, .FlexibleHeight]
#5
0
In Swift 4, the below works.
在Swift 4中,以下工作原理。
cell.cellUIView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
Note:
cellUIView
is aUIView
I added to thecontentView
of the prototype cells.注意:cellUIView是我添加到原型单元格的contentView的UIView。
#1
7
If you are overriding the layoutSubviews
or another method, don't forget to call it's super:
如果您要覆盖layoutSubviews或其他方法,请不要忘记将其称为超级:
override func layoutSubviews() {
//...
super.layoutSubviews()
}
Not doing this will result in the problem you are facing.
不这样做会导致您遇到的问题。
#2
1
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.
单元格将自动与表格视图的宽度相同。所以没有调整大小的可能是表格视图。您需要为其提供适当的约束(如果使用Autolayout,iOS 6中的默认值)或自动调整遮罩(否则),以便调整大小以响应顶层视图的大小调整以补偿设备旋转。
#3
1
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.
在旋转时自动调整自定义单元格时,我也遇到了同样的问题。战斗结束后,我得到了解决方案作为authorize cell.contentView,因为我将我的视图作为子视图添加到cell.contentview中。
I used following code and my code works fine :)
我使用以下代码,我的代码工作正常:)
cell.contentView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin;
#4
1
For swift 2, it will be:
对于swift 2,它将是:
cell.contentView.autoresizingMask = [.FlexibleWidth, .FlexibleHeight]
#5
0
In Swift 4, the below works.
在Swift 4中,以下工作原理。
cell.cellUIView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
Note:
cellUIView
is aUIView
I added to thecontentView
of the prototype cells.注意:cellUIView是我添加到原型单元格的contentView的UIView。