xcode UITableViewCell:原型单元格的自定义行高
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11989329/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
UITableViewCell: Custom Row Height for prototype cell
提问by Brabbeldas
In my storyboard file I am designing multiple prototype cells in a UITableView. Each cell has its own unique Cell Identifier.
在我的故事板文件中,我正在 UITableView 中设计多个原型单元格。每个单元格都有自己唯一的单元格标识符。
Depending on the section and the row I dequeue one of the prototype cells in method - tableView:cellForRowAtIndexPath:
根据部分和行,我将方法中的原型单元格之一出列 - tableView:cellForRowAtIndexPath:
For most of the prototype cells I have not changed the Row Height. On my storyboard, their height seems to be determined by the property 'Row Height' under 'Size Inspector' of UITableView.
对于大多数原型单元格,我没有更改行高。在我的故事板上,它们的高度似乎由 UITableView 的“Size Inspector”下的“Row Height”属性决定。
For one prototype cell I have changed the height through the property 'Row Height' under 'Size Inspector' of the specific UITableViewCell. The checkbox 'Custom' is also checked.
对于一个原型单元格,我通过特定 UITableViewCell 的“Size Inspector”下的“Row Height”属性更改了高度。复选框“自定义”也被选中。
On my storyboard this seem to work well. But during runtime when my cells are being dequeued and added to the TableView, all cells get the default row height.
在我的故事板上,这似乎运作良好。但是在运行时,当我的单元格出列并添加到 TableView 时,所有单元格都会获得默认的行高。
Now, I am aware of the method tableView:heightForRowAtIndexPath: which is being mentioned in other posts but it seems a little odd to use as I am setting a custom row height in my storyboard already.
现在,我知道其他帖子中提到的 tableView:heightForRowAtIndexPath: 方法,但使用起来似乎有点奇怪,因为我已经在我的故事板中设置了自定义行高。
Does somebody know why this property is not working? Is this property maybe mend to be used in different situations?
有人知道为什么这个属性不起作用吗?这个属性可能会在不同情况下使用吗?
Thanks
谢谢
采纳答案by Martin R
heightForRowAtIndexPath
is called (for each row of the table) beforethe cells are displayed, i.e. before cellForRowAtIndexPath
is called. That is necessary to compute the layout of the underlying scrollview, the scroll indicators etc.
heightForRowAtIndexPath
在显示单元格之前调用(对于表格的每一行),即 beforecellForRowAtIndexPath
被调用。这是计算底层滚动视图、滚动指示器等的布局所必需的。
回答by enreas
If you want to use Interface Builder in Xcode 5 to change the height of the rows in a table view without code you can do it in two places:
如果你想在 Xcode 5 中使用 Interface Builder 在没有代码的情况下更改表格视图中行的高度,你可以在两个地方进行:
- Select the table view, show the Size inspectorand type it in Row Height, in the Table View Sizesection.
- 选择表格视图,显示大小检查器并在表格视图大小部分的行高中输入它 。
- Select the prototype cell, show the Size inspector, check Customin the Table View Sizesection and type the row height in the associate text field.
- 选择原型单元格,显示Size inspector,在Table View Size部分选中Custom并在关联文本字段中输入行高。
Could it be that you're using the second method? Try to use the first method to set the default height of all the rows in the table view and the second to tell Interface Builder about the exceptions.
难道你用的是第二种方法?尝试使用第一种方法设置 table view 中所有行的默认高度,第二种方法告诉 Interface Builder 有关异常的信息。