Reputation: 104
Is it possible to use this feature without using text related views? This would be to not have to calculate the height, but instead let the cell self-size using subviews with constant height constraints, and eventually changing those height constraints at runtime.
Upvotes: 0
Views: 72
Reputation: 194
Yes you can do that. First Add constraints to subviews and add the following code in .m file.
-(CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath{ return UITableViewAutomaticDimension; }
Upvotes: 0
Reputation: 6885
Yes,you could build a tableviewcell with dynamic height.
1.use constraints to configure your tableviewcell's subviews
2.add a line of code In viewdidload method:
self.tableView.rowHeight = UITableViewAutomaticDimension
3.in some cases you must add another line of code In viewdidload method:
self.tableView.estimatedRowHeight = 40 //or any value other than your tableviewcell's height in IB.
Upvotes: 0
Reputation: 5858
The proper way to handle dynamic cell height changes in a table view is through tableView:heightForRowAtIndexPath:
in UITableViewDelegate
. You can grab the height from the subviews but you have to link that value to the index path of the cell.
Upvotes: 1