Resetting custom UITableViewCell height when iPhone is rotated

后端 未结 1 404
忘掉有多难
忘掉有多难 2021-02-10 05:42

I am overloading the delegate method -tableView:heightForRowAtIndexPath: and using -sizeWithFont:constrainedToSize: to programmatically set the height

1条回答
  •  遥遥无期
    2021-02-10 06:22

    It's less than optimal, but the simplest solution is to call -reloadData on the table.

    A better solution would be to call -beginUpdates, -deleteRowsAtIndexPaths:withRowAnimation:, -insertRowsAtIndexPaths:withRowAnimation:, and -endUpdates or simply -reloadSections:withRowAnimation: if targeting 3.0 only. This will add animation.

    Edit: And you will also need a proper tableView:heightForRowAtIndexPath:

    - (CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
        CGSize textSize = [[self textForRowAtIndexPath:indexPath] sizeWithFont:[UIFont systemFontOfSize:14] constrainedToSize:CGSizeMake([tableView frame].size.width - 20, 500)];
        return textSize.height + 13.0f;
    }
    

    (where textForRowAtIndexPath: is a method that returns the cell's text)

    0 讨论(0)
提交回复
热议问题