我有一个习惯UITableViewCell
。我想访问单元格的属性,即UILabel
等。我尝试插入以下代码:
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
CategorieCell *customCell = (CategorieCell *)[tableView cellForRowAtIndexPath:indexPath];
return ...
}
当我运行该应用程序时,它崩溃了而没有提供错误详细信息。问题出在我正在创建的新customCell上。有没有其他方法可以访问customCell.m
对象?
关于崩溃,请注意,您正在使用cellForRowAtIndexPath:wich是必须实现的UITableViewDatasource方法,默认情况下此方法调用heightForRowAtIndexPath,因此它将变为递归
我假设您希望在此方法中使用自定义单元格,以便从中获取高度。实现此目的的最佳方法是在CategorieCell上编写一个类方法,该方法为您提供具有某些数据的单元格的高度。
另一个选择是使用代码提取方法以获取uitableviewcell例如
(CategorieCell*) categorieCellForIndex:(NSIndex)index selected:(BOOL)selected{
...
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句