Blade
Blade

Reputation: 1437

TableView throws error when trying to implement dymanic cell height

I'm trying to customize the height of my tableView cells. I tried a few tutorials, but nothing seems to work. "Funny thing" is that the error message is always the same. Here is the code I'm using atm:

#define PADDING 10.0f
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath     *)indexPath
{
NSString *text = [self.tabelle objectAtIndex:indexPath.row];
CGSize textSize = [text sizeWithFont:[UIFont systemFontOfSize:14.0f] constrainedToSize:CGSizeMake(self.tableView.frame.size.width - PADDING * 3, 1000.0f)];

return textSize.height + PADDING * 3;

}

And this is the error message I get:

2012-05-09 20:01:55.553 APP[436:f803] -[APP sizeWithFont:constrainedToSize:]: unrecognized selector sent to instance 0x687f5f0
2012-05-09 20:01:55.555 APP[436:f803] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[APP sizeWithFont:constrainedToSize:]: unrecognized selector sent to instance 0x687f5f0'
*** First throw call stack:
(0x128e022 0x1846cd6 0x128fcbd 0x11f4ed0 0x11f4cb2 0x42c9 0x3ab688 0x3ad862 0x25b66d    0x25b167 0x2f4d 0x34e8 0x29638f 0x2965eb 0x2a6ff1 0x2a785f 0x2a79e1 0x3c55c2 0x20bd21 0x128fe42 0xea679 0xf4579 0x794f7 0x7b3f6 0x108160 0x1cbe84 0x1cc767 0x1db183 0x1dbc38 0x1cf634 0x2181ef5 0x1262195 0x11c6ff2 0x11c58da 0x11c4d84 0x11c4c9b 0x1cbc65 0x1cd626 0x24a5 0x1d35)
terminate called throwing an exception

My first thought was that it doesn't like me setting the font size of the labels in the

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

But that doesn't seem to be the case

Upvotes: 0

Views: 202

Answers (1)

Philippe Sabourin
Philippe Sabourin

Reputation: 8075

The reason you're getting this error is cause this:

[self.tabelle objectAtIndex:indexPath.row];

Will return the custom object you have in tabelle, not an NSString, and you're calling an NSString method on it. Maybe you mean to use

[[self.tabelle objectAtIndex:indexPath.row] Name]

or

[[self.tabelle objectAtIndex:indexPath.row] m_yolo]

Depending on which text you want to base the size on.

EDITED TO USE THE CUSTOM OBJECTS IN TABELLE

Upvotes: 2

Related Questions