ios 怎么设置一个cell的宽度

2025-05-10 08:52:50
推荐回答(2个)
回答1:

cell的实际宽度是跟随tableView的宽度变化的,无法设定。
也就是tableView的宽度是 fWidth,那么cell.ContentView的宽度也是fWidth
你只需要把cell.contentView看成是一块frame = (0,0,fWidth,customHight)的画布,
然后在这个画布上布局你所需要的subviews。

回答2:

tableView beginUpdate]

[tableView endUpdate]

之后tableView就会再次调用heightForRowAtIndexPath,这时候你就可以返回正确的cell高度给它了。