I have a UITableViewCell that I need to resize as the user types. The cell has a UITextView as a subview.
Inside heightForRowAtIndexPath, I need to check whether the current cell is nil or initialized.
If it’s nil, I calculate its height based on text in a string property.
If it’s NOT nil (i.e. initialized), I want it to retrieve the text property of the cell’s subview (I know I can access it if the cell is initialized).
How can I check if a UITableViewCell is nil or not within heightForRowAtIndexPath:? I tried
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
if ([overviewTableView cellForRowAtIndexPath:indexPath] !=nil)
{ NSLog(@"YEEHAW!");
}
}
but it results in an error (probably because cellForRowAtIndexPath: expects the cell to be initialized, not nil). Also, I noticed that cellForRowAtIndexPath: calls heightForRowAtIndexPath: (resulting in a recursive loop).
I’ve seen many “alternatives” on the web, but I was just wondering whether this approach is would work (or is valid at all).
Thanks in advance!
You could check if the
indexPathfor the cell of interest is visible or not:Hope this helps!