【发布时间】:2014-03-10 09:18:24
【问题描述】:
我目前无法通过代码更改UITableView 的高度。
默认设置为320宽度和289高度。
在代码中,cellForRowAtIndexPath 的末尾有...
self.tableView.frame = CGRectMake(self.tableView.frame.origin.x, self.tableView.frame.origin.y, self.tableView.frame.size.width, [self.myPlayers count] * cell.frame.size.height);
就在我归还单元格之前。
我写信给 NSLog,它的宽度为320,高度为88 2 行,这是正确的。但是,我的UITableView 的大小显然和往常一样(高度289)。
我需要做什么才能完成这项工作?
谢谢!
【问题讨论】:
-
cellForRowAtIndexPath 是 Cell 而非表格的方法。
-
你到底什么时候想换框架...?
-
如果您的单元格高度是动态的,您可以在 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 中计算高度。通过使用 CGFloat cellHeight = [self tableView:tableView heightForRowAtIndexPath:indexPath];。您最好将计算出的高度存储到数组中,并使用它来计算 tableview 的高度
-
你的表是在 UITableViewController 还是 UIViewController 中?在 UITableViewController 你不能改变框架......因为 self.view == self.tableView
标签: ios cocoa uitableview height