這是我的故事:Probleme具有高度的UITableViewCell
我有一個問題,我IUTableViewCell
的大小。當我添加幾個單元格時,單元格會自動調整大小。
任何答案可以理解的:)
我的代碼來調整:
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPathInCellTable:(NSIndexPath *)indexPath {
CustomCell *cell = (CustomCell*) [self tableView:tableView
cellForRowAtIndexPath:indexPath];
CGSize size;
// SIZE HEIGHT TEXT
size = [cell.color.text sizeWithAttributes:
@{NSFontAttributeName:
[UIFont systemFontOfSize:12.0f]}];
// SIZE HEIGHT FOR CELL
CGRect frame = [cell frame];
frame.size.height += size.height;
[cell setFrame:frame];
// SIZE HEIGHT IMG
CGRect frame = [cell.img frame];
frame.size.height = 69;
frame.size.width = 69;
[cell.img setFrame:frame];
if (indexPath.row == 0) [self setHeightTableView:0];
_tableHeightConstraint.constant += cell.frame.size.height;
return cell.frame.size.height;
}
有一些截圖:
我第一次添加單元格一切細
同爲第二單元,一切都很好
還有問題就來了
很確定這是重複的;如果我記得,在tableView:heightForRowAtIndexPathInCellTable:內部調用'[self tableView:tableView cellForRowAtIndexPath:indexPath]'是不好的,因爲iOS在獲取單元格之前需要高度。 – RobP