Search code examples
iosobjective-cuitableviewheightforrowatindexpath

Trying to set the height of a cell in cellForRowAtIndexPath, after heightForRowAtIndexPath


Since heightForRowAtIndexPath is called before cellForRowAtIndexPath, I was assuming that if I wanted to modify the height from within cellForRowAtIndexPath, I could do so. It seems I can't. I've tested via NSLog and if I change cell.frame.size.height, the change is stored in there properly, but the cell itself doesn't take on the new size (it's using the one I set in heightForRowAtIndexPath).

Is there another method that would adjust the cell's height that's called at some point after cellForRowAtIndexPath? If not, is there another way around this? I need to use cellForRowAtIndexPath since I'm deciding on the fly whether to randomly add an image to each cell in turn.


Solution

  • You should put the code that randomly decides to add an image in your heightForRowAtIndexPath method instead.

    Use a NSMutableDictionary to keep track of the NSIndexPath's that use images.