I need to set the height of a cell after creation of the cell since I will not know until then how high it needs to be. My question is, when does tableView:heightForRowAtIndexPath: get called? Is it after tableView:cellForRowAtIndexPath: has returned so I can get the required height from my custom cell class? I am away from my Mac right now it the thought just occured to me to ask about this.
Just the 2nd cell out of 3 needs to be dynamic in height. I haven't had much time the past few days to actually work on this, but I can't wrap my head around a solution except to get the needed height before the view loads, but was hoping for something quicker that I might have missed.
I just implemented custom cell height in something I was working on. I could only figure out how to set the hight when the view loads. I wasn't able to do it after the view loaded. There may be a way, but if there is I couldn't figure it out either.
I think if you call reloadData on the UITableView, it will query the delegate (or datasource? can't remember) for the height of the row again. reloadData may end up calling viewWillAppear, in which case it wouldn't be any better of a workaround than the solution you already have. I'm not sure though.
You need to figure out the height of any dynamic height cells independent of the actual cell. This kind of sucks but that's the way it is. tableView:heightForRowAtIndexPath will be called at various times that you can't predict and it will certainly be called at times that some of your cells don't exist.
So if your cell has a variable amount of text in it or an image that can be different heights you need to determine the height of the content independently of the cell object itself.
If you have implemented heightForRowAtIndexPath: the tableview will call it for all of the rows in order to figure out the height of the entire table. It will do this every time that reloadData is called by your code.