Reputation: 35
Tableview has three types of custom cells with dynamic height. I want to set the row height using like tableView.rowHeight = 100
in cellForRowAtIndex()
method.
Is this appropriate?
Upvotes: 0
Views: 288
Reputation: 214
1.Define auto layout constraints for your prototype cell 2.Specify the estimatedRowHeight of your table view 3.Set the rowHeight of your table view to UITableViewAutomaticDimension
Do these code in viewDidLoad
tableView.estimatedRowHeight = 68.0(actual height of your prototype cell)
tableView.rowHeight = UITableViewAutomaticDimens
Upvotes: 2
Reputation: 318814
No, that is not how you need to do it. Never make any attempt to set any table attributes inside the cellForRowAtIndexPath
method. Just create and return a cell.
If your cells have varying heights, simply implement the heightForRowAtIndexPath
method and return the appropriate height for a given indexPath.
If all rows have the same height, then set the table view's rowHeight
property in viewDidLoad
or other appropriate place.
Upvotes: 0