iPhone + UITableView +行高
我使用以下代码设置 UITableView
的行高,
[tableView setRowHeight: 100.00];
我在 UITableView
中使用单行作为分隔符。
即使设置了上面的高度,行的高度也不会改变。
I am setting the row height of my UITableView
using following code
[tableView setRowHeight: 100.00];
I am using the single line as separator in the UITableView
.
Eventhough setting the height above, height of row does not get change.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
您应该实现
委托方法。并在那里返回 100.0。
You should implement
delegate method. and return 100.0 there.
如果所有行的高度相似,则应避免使用
heightForRowAtIndexPath
并使用rowHeight
属性。根据文档:例如,在 UITableViewController 子类中,可以在 viewDidAppear 方法中完成(
UITableViewController 具有对 tableView 的引用):
You should avoid the
heightForRowAtIndexPath
if all your rows are of similar height and use therowHeight
property. According to the documentation:In the UITableViewController subclass it could be done, for instance, in the
viewDidAppear
method (theUITableViewController
has a reference to the tableView):当单元格首次显示时,行高被烘焙到单元格中。
设置数据源之前是否设置了UITableView#rowHeight?
如果没有,请这样做。
如果出于某种原因您不能,您的另一个选择是在设置行高后调用 UITableView#reloadData。
The row height is baked into the cells when they are first displayed.
Did you set UITableView#rowHeight before setting the data source?
If not, do so.
If for whatever reason you can't, your other option is to call UITableView#reloadData after setting the row height.
我确实喜欢这样做,这里的
tableobj
只是我的应用程序中的UITableView
对象。或者在
numberOfRowsInSection:
中处理它,例如:因为在设置数据源之前设置了
rowHeight
。它对我有用(对于相同的行高)。I did like this, here
tableobj
is nothing butUITableView
object in my application.Or handle it in
numberOfRowsInSection:
like:Because set the
rowHeight
before setting the data source. It worked for me (for equal row heights).更好、更干净的解决方案是实现委托函数(如果你的 UITableView 有很多行,也许不是最好的解决方案......)。
另外,认为 UITableVieCell 是 UIView,所以你可以首先改变它们的高度...
代表在 iPhone 开发中非常强大,这里是 UITableViewDelage:
http://developer.apple.com/iphone/library/documentation/uikit/reference/UITableViewDelegate_Protocol/Reference/Reference.html
您还可以更改 indentForRow、displayCellForRow、heightForRow、编辑内容......
The better and cleaner solution is to implement the delegate function (Maybe not the best one if your UITableView has many rows ...).
Also, think that UITableVieCell are UIView so you could change their height firstly...
Delegates are very powerful in iPhone dev, here the UITableViewDelage:
http://developer.apple.com/iphone/library/documentation/uikit/reference/UITableViewDelegate_Protocol/Reference/Reference.html
You can also change the indentForRow, displayCellForRow, heightForRow,edit stuff .....
我认为 UITableView 中没有这样的方法...
相反,您可以使用属性 rowHeight...
尝试,
tableView.rowHeight =100;
I dont think there is such a method in UITableView...
Instead you can use the property rowHeight...
Try,
tableView.rowHeight =100;