使用 IB 调整大小构建自定义 UITableViewCell?
我已确保单元格的自动调整大小蒙版允许灵活的宽度,但当设备旋转时,单元格的大小不会调整。
我还验证了表格视图的大小已调整,问题直接出在单元格上。
这是我用来创建单元格的代码:
if (cell == nil) {
// Load the top-level objects from the custom cell XIB.
NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"MetaTableViewCell" owner:self options:nil];
// Grab a pointer to the first object (presumably the custom cell, as that's all the XIB should contain).
cell = [topLevelObjects objectAtIndex:0];
}
有人能想到可能出了什么问题吗?
使用 IB 创建的单元是否从未调整过大小?
I have ensured the autosizing mask of my cell allows flexible width, but when the device is rotated the Cells are not resized.
I have also verified the tableview is resized, the problem is directly with the cells.
This is the code I am using to create the cells:
if (cell == nil) {
// Load the top-level objects from the custom cell XIB.
NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"MetaTableViewCell" owner:self options:nil];
// Grab a pointer to the first object (presumably the custom cell, as that's all the XIB should contain).
cell = [topLevelObjects objectAtIndex:0];
}
Can someone think of what might be wrong?
Are cells created using IB not resized ever?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果单元格的高度未调整大小,我建议您在旋转后修改
UITableView
委托方法。-
请确保在旋转发生时调用
[tableView reloadData];
。If its the height of the cell that is not resized I suggest you to modify the
UITableView
delegate method after rotation.-
Pls make sure that you call
[tableView reloadData];
when rotation has taken place.如果我理解你的问题,你想改变 UITableViewCells 的高度,对吧?尝试在 TableView 的委托中添加这一行:
我遇到了同样的问题。如果您在 IB 中设置大小,您可以在其中放置更多内容,但加载时它仍然会询问您的委托的高度。如果您的委托没有实现此方法,它将仅采用默认高度。
If i understand your question, you want to change the height of UITableViewCells, right? Try adding this line in your TableView's delegate:
I was having the same problem. If you set the size in IB, you can put more stuff in there, but it will still ask your delegate for the height when loading. If your delegate does not implement this method, it will simply take the default height.