I have a Table View called todoTableView
with cells that created by the user.
Each cell has Text View.
I want to change the height of the cell by the content of
Bound Your textview
with cell
from all sides using marginal constraints.(Leading, Trailing, Top and Bottom constraints)
In viewDidLoad() add the following.
tableView.estimatedRowHeight = 44.0
tableView.rowHeight = UITableViewAutomaticDimension
This will make your cell size according to your textview content size.
Have a look at result :
You don't need to write heightForRowAtIndexPath.
You should also implement heightForRowAtIndexPath
:
func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat
{
return // Calculate your custom row height here.
}
Irfan's answer didn't work for me.
It works after I go to Size Inspector and check "Automatic" for "Row Height".