我使用以下代码

设置 UITableView 的行高
[tableView setRowHeight: 100.00];

我在 UITableView 中使用单行作为分隔符。

尽管设置了上面的高度,行的高度不会改变。

有帮助吗?

解决方案

你应该实施

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath

委托方法。然后返回100.0。

其他提示

如果所有行的高度相似,并且使用 rowHeight 属性,则应避免使用 heightForRowAtIndexPath 。根据文件:

  

使用tableView:heightForRowAtIndexPath:而不是rowHeight会对性能产生影响。每次显示表视图时,它都会在每个行的委托上调用tableView:heightForRowAtIndexPath:这会导致表视图具有大量行(大约1000或更多)的显着性能问题。

在UITableViewController子类中,例如,可以在 viewDidAppear 方法中完成( UITableViewController 具有对tableView的引用):

self.tableView.rowHeight = 79.f;

首次显示时,行高会被烘焙到单元格中。

在设置数据源之前是否设置了UITableView#rowHeight?
如果没有,请这样做 如果由于某种原因你不能,你的另一个选择是在设置行高后调用UITableView#reloadData。

我确实喜欢这个,这里 tableobj 只是我应用程序中的 UITableView 对象。

- (void)viewDidLoad
{
    [super viewDidLoad];
    [tableObj setRowHeight:100.0f];
}

或者在 numberOfRowsInSection:中处理它,如:

- (NSInteger)tableView:(UITableView *)tblView numberOfRowsInSection:(NSInteger)section {
    [tableObj setRowHeight:100.0f];
    return [soandso count]; // soandso is my object
}

因为在设置数据源之前设置 rowHeight 。它对我有用(等排高度)。

更好更清洁的解决方案是实现委托功能(如果您的UITableView有很多行,可能不是最好的...)。

另外,认为UITableVieCell是UIView所以你可以先改变他们的身高......

代表在iPhone开发中非常强大,这里是UITableViewDelage:

http://developer.apple的.com / iphone /库/文档/ UIKit的/参照/ UITableViewDelegate_Protocol /参考/的reference.html

您还可以更改indentForRow,displayCellForRow,heightForRow,编辑内容......

我认为UITableView中没有这样的方法...

相反,您可以使用属性rowHeight ...
尝试, tableView.rowHeight = 100;

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top