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

标签 ios dynamic height tableview cell

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

但好像不是这样

最佳答案

您收到此错误的原因是:

[self.tabelle objectAtIndex:indexPath.row];

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

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

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

取决于您要基于哪些文本来调整大小。

经过编辑以在 TABELLE 中使用自定义对象

关于ios - 尝试实现动态单元格高度时 TableView 抛出错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10521720/

相关文章:

ios - 当我点击 swift 3 中的提交按钮时如何重复文本字段

ios - 更改 UIAlertViewController 色调颜色

html - 容器 div 未在属性最小高度上扩展

jquery - 垂直居中文本 (jQuery)

css - 如何通过屏幕高度而不是浏览器高度设置高度

ios - 使用 Google Maps SDK 的哪个方法,例如 MapKit 的 struct MKCooperativeRegion

ios - 如何找到谷歌地图的旋转角度

dictionary - 映射动态值类型?

python - 尝试为动态添加的类覆盖 __getattr__ 但仅能正常工作

c - 无法分配动态内存段错误