现在的位置: 首页 > 综合 > 正文

改变tableViewCell高度的方法

2017年12月09日 ⁄ 综合 ⁄ 共 419字 ⁄ 字号 评论关闭

1.最常用方法,重写一下方法

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

但是这种方法不能灵活地解决问题,因为你只能固定在这个位置改,本人就试过不会在此获取到想要地高度。

2.比较灵活地办法,直接修改tableview地属性。

假如我定义了一个tableview叫costTableView,那么我只需要在一下重写方法中:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

加上一句代码:

self.costTableView.rowHeight = projCell.backgroundView.frame.size.height;

就可以调整高度了,而无需重写第一个方法。

抱歉!评论已关闭.