Problem Cause:
The problem is that the cell has not been created yet. TableView first calculates the height for row and then populates the data for each row, so the rows array has not been created when heightForRow method gets called. So your app is trying to access a memory location which it does not have the permission to and therefor you get the EXC_BAD_ACCESS
message.
How to achieve self sizing TableViewCell
in UITableView
:
Just set proper constraints for your views contained in TableViewCell
's view in StoryBoard
. Remember you shouldn't set height constraints to TableViewCell's root view, its height should be properly computable by the height of its subviews -- This is like what you do to set proper constraints for UIScrollView
. This way your cells will get different heights according to their subviews. No additional action needed