0

我正在尝试自定义我的 tableView 单元格的高度。我尝试了一些教程,但似乎没有任何效果。“有趣的事情”是错误信息总是一样的。这是我正在使用 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;

}

这是我收到的错误消息:

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

我的第一个想法是它不喜欢我在

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

但情况似乎并非如此

4

1 回答 1

2

您收到此错误的原因是:

[self.tabelle objectAtIndex:indexPath.row];

将返回您在 tabelle 中拥有的自定义对象,而不是 NSString,并且您正在对其调用 NSString 方法。也许你的意思是使用

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

或者

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

取决于您要基于哪个文本来确定大小。

编辑使用 TABELLE 中的自定义对象

于 2012-05-09T18:14:58.283 回答