I wand to know the content of the cell when returning the heightForRowAtIndexPath. In this function how do I get the cell object?
- (CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
}
If I try this
[tableView cellForRowAtIndexPath:indexPath]
it fails and goes off in an infinite loop.
Any idea?
To completely prevent selection of the UITableViewCell , have your UITableViewDelegate implement tableView:willSelectRowAtIndexPath: . From that method you can return nil if you do not want the row to be selected. This prevents the row from being selected and tableView:didSelectRowAtIndexPath: from being called.
Call self (the delegate) rather than the tableView itself.
id cell = [self tableView:tableView cellForRowAtIndexPath:indexPath];
Use: func dequeueReusableCellWithIdentifier(identifier: String) -> AnyObject?
of UITableView
.
Don't use: func dequeueReusableCellWithIdentifier(identifier: String, forIndexPath indexPath: NSIndexPath) -> AnyObject
Possible Reason: heightForRowAtIndexPath
gets called before cellForRowAtIndexPath
and this method uses the index path to perform additional configuration based on the cell’s position in the table view. But since, there is still no cell yet, hence it goes to infinite loop I think.
The cell hasn't been created when heightForRowAtIndexPath:
is called, so there's no way to "get" a cell. Instead, look at your model and determine the height of the cell that way.
If you're concerned about long strings and needing more vertical space in your cell, consider using sizeWithFont:forWidth:lineBreakMode:
. Docs here: https://developer.apple.com/library/ios/#documentation/uikit/reference/NSString_UIKit_Additions/Reference/Reference.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With