22

我正在UITableView使用以下代码设置我的行高

[tableView setRowHeight: 100.00];

我使用单行作为分隔符UITableView

即使设置了上面的高度,行的高度也不会改变。

4

6 回答 6

65

你应该实施

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

委托方法。并在那里返回 100.0。

于 2009-10-28T08:40:40.840 回答
23

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

使用 tableView:heightForRowAtIndexPath: 代替 rowHeight 会影响性能。每次显示表视图时,它都会在委托上为其每一行调用 tableView:heightForRowAtIndexPath:,这可能会导致具有大量行(大约 1000 或更多)的表视图出现严重的性能问题。

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

self.tableView.rowHeight = 79.f;
于 2011-01-18T23:55:19.367 回答
7

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

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

于 2009-12-09T02:45:28.150 回答
3

我确实喜欢这样,这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在设置数据源之前设置了。它对我有用(对于相同的行高)。

于 2012-11-07T12:55:32.717 回答
0

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

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

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

http://developer.apple.com/iphone/library/documentation/uikit/reference/UITableViewDelegate_Protocol/Reference/Reference.html

您还可以更改 indentForRow、displayCellForRow、heightForRow、edit stuff .....

于 2010-07-10T08:18:31.643 回答
-5

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

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

于 2009-10-28T08:41:12.330 回答