您的位置:首页 > 产品设计 > UI/UE

关于UITableViewCell (xib) 自适应高度的问题

2016-05-09 00:04 591 查看
(CGFloat)tableView:(UITableView )tableView heightForRowAtIndexPath:(NSIndexPath )indexPath{

// NSLog(@”heightForRowAtIndexPath”);

// carCell cell = (carCell )self.protoTypeCell;

// carCell *cell = [carCell cellWithTableView:tableView indexPath:indexPath];

// cell.car = [self.cars objectAtIndex:indexPath.row];

// NSLog(@”%p”,cell);

// return [cell.contentView systemLayoutSizeFittingSize:UILayoutFittingCompressedSize].height;

NSLog(@”%p”,self.protoTypeCell);

return [self.protoTypeCell.contentView systemLayoutSizeFittingSize:UILayoutFittingCompressedSize].height;(用一个成员变量来记录cell ,避免在cellforrowatindexpath调用后,再调用heightforrowatindexpath时候再创建一个cell实例,浪费内存);

}

(CGFloat)tableView:(UITableView )tableView estimatedHeightForRowAtIndexPath:(NSIndexPath )indexPath{

return 100;

}(初始化的时候 , 避免一下全部计算出cell 的高度)

如果想在UITableViewCell中点击的时候拿到点击了第几行,我们可以通过UITableViewCell.Tag 来拿到对应的。in indexPath.row.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: