为什么UITableView的最后一个单元格的高度被用于剩余的空单元格?
我的细胞都有不同的高度,由用户input的文本确定。
最后一个细胞的高度似乎决定(改变)所有剩余空白细胞的高度。
它看起来没有调用heightForRowAtIndexPath这些剩余的空单元格,也不是CFRAIP。
有谁知道如何解决这个问题或为什么发生?
把这段代码放在放置tableview的viewController的viewDidLoad中。
self.tableView.tableFooterView = [[UIView alloc] init];
我也遇到了这个问题。 这令我非常沮丧。 经过一番考虑,我认为它可能是一个tableview的function,它显示空白单元格。 使用空白单元格的最后一个单元格高度是合理的。 否则,select使用什么样的高度?
我认为这是不能接受的显示黑细胞。 如果你不喜欢像我这样的风格,你可以试试这个摆脱空白的单元格:
self.tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
要么
self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone; //then add view for separator line by yourself
要么
UITableView *tableView = [[UITableView alloc] initWithFrame:self.tableView.frame style:UITableViewStyleGrouped]; tableView.backgroundColor = self.tableView.backgroundColor; self.tableView = tableView;
如果您必须显示空白单元格并控制高度,也许这是添加其他单元格的最简单的方法/解决方法。 例如:
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return self.dataArray == nil || self.dataArray.count == 0 ? 1 : self.dataArray + 1; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ if(indexPath.count == self.dataArray.count){ //the last cell cell = [[UITableViewCell alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 50)]; } else { cell = .... //as uausal } return cell; } -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{ if(indexPath.count == self.dataArray.count){ return 50; } else { return xxx; //as usual } }
现在我们可以控制任何高度!
希望它可以帮助你。
你也可以参考这个链接: 我如何修改纯UITableView中“空”单元格的外观?