我有一个自定义的UITableViewCell
。我想访问单元格属性,即 UILabel
等。我尝试插入以下代码:
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
CategorieCell *customCell = (CategorieCell *)[tableView cellForRowAtIndexPath:indexPath];
return ...
}
当我运行该应用程序时,它崩溃了,但没有给我错误详细信息。问题出在我正在创建的新的 customCell 上。还有其他方法可以访问 customCell.m
对象吗?
最佳答案
关于崩溃,请注意,您使用的是 cellForRowAtIndexPath: 这是您必须实现的 UITableViewDatasource 中的一个方法,该方法默认调用 heightForRowAtIndexPath,因此它将成为递归
我假设您希望在此方法中使用自定义单元格,以便从中获取高度。 实现此目的的最佳方法是在 CategorieCell 上编写一个类方法,该方法为您提供具有特定数据的单元格的高度。
其他选项是提取带有代码的方法以获取 uitableviewcell 例如
(CategorieCell*) categorieCellForIndex:(NSIndex)index selected:(BOOL)selected{
...
}
关于ios - 访问 heightForRowAtIndexPath 中的自定义单元格属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28355066/