我在 UITableView 中使用静态单元格布局。在工作流程中,我需要处理特定单元格的属性。所有单元格都有一个标识符,但我没有找到使用标识符实际寻址单元格的方法。
谢谢, em
最佳答案
cellForRowAtIndexPath:
不可靠的原因可能是这个(来自文档):
An object representing a cell of the table or nil if the cell is not visible or indexPath is out of range.
如果您请求一个在屏幕上不可见的单元格,它可能已从表格 View 中清除。
由于您提到您在 tableview 中使用静态单元格布局(我假设您不依赖单元格重用),您可以考虑将单元格保留为私有(private)属性:
在私有(private)接口(interface)中:
@interface MyViewController ()
@property (nonatomic, readonly) MyTableViewCellClass *myStaticCell;
@end
在实现中:
@implementation MyViewController {
MyTableViewCellClass* _myStaticCell;
}
- (MyTableViewCellClass*) myStaticCell {
if (!_myStaticCell) {
// Initialize _myStaticCell
}
return _myStaticCell
}
然后,您可以在调用 tableView:cellForItemAtIndexPath:
时以及需要修改它时调用此延迟加载属性。
请注意,仅当您的 TableView 包含静态内容且不依赖单元格重用时才推荐使用此方法。
关于ios - 如何处理特定的 UITableViewCell?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22832995/