在做项目的时候我们往往会遇到cell高度自适应的问题,楼主以前也写过,但是由于时间问题和记忆问题将之跑到九霄云外了,于是上网查阅资料但是发现网上资料几乎是千篇一律的又长又臭,简直难以看下去,于是决定写上重要方法已做记录,下面上代码
我们只需要在-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath重新计算高度就行
TableViewCell *cell = (TableViewCell *)[self tableView:self.table cellForRowAtIndexPath:indexPath];
return cell.frame.size.height;
当然不仅仅是上面一段,我们还需要在
-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath中重新计算一下cell的frame的高度,否则你会发现你的cell高度是默认的44