Ios TableView在尝试实现动态单元格高度时抛出错误

Ios TableView在尝试实现动态单元格高度时抛出错误,ios,dynamic,height,tableview,cell,Ios,Dynamic,Height,Tableview,Cell,我正在尝试自定义tableView单元格的高度。我尝试了一些教程,但似乎没有任何效果。“有趣的是”错误信息总是一样的。这是我使用atm的代码: #define PADDING 10.0f - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { NSString *text = [self.tabelle objectAtIndex:indexPath.

我正在尝试自定义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;

}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
这是我收到的错误信息:

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
我的第一个想法是,它不喜欢我设置标签的字体大小

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

但情况似乎并非如此

出现此错误的原因是:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
[self.tabelle objectAtIndex:indexPath.row];
将返回tabelle中的自定义对象,而不是NSString,并且您正在对其调用NSString方法。也许你想用

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
[[self.tabelle objectAtIndex:indexPath.row] Name]

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
取决于要基于哪个文本设置大小

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

编辑以使用选项卡中的自定义对象

谢谢,但现在我遇到另一个错误:**由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:'-[app textLabel]:未识别的选择器发送到实例0x6a99400'是否使用常规UITableViewCell?你能复制整个CellForRowatineXpath方法吗?当然,给你。但现在它有点问题,我总是要在它显示任何东西之前单击“显示下一个X项”。我不知道那里出了什么问题。我已经编辑以反映Tabelle中的内容,从我在您的代码中可以看出。我不确定要使用哪个字符串来调整单元格的大小。第20、21、23行您使用的是stringWithFormat,而没有实际添加任何内容。不需要这样做,您可以直接将字符串分配给标签。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath