ios - 如何处理特定的 UITableViewCell?

标签 ios objective-c uitableview

我在 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/

相关文章:

ios - 附加图像后,可选的 UIImage 数组为 nil

ios - 我可以设置 UITextField 以在按下 Return 时触发 UIBarButtonItem 的操作

ios - UIButton 没有出现在 iPhone 5S 上

ios - YTPlayerView自定义按钮开始停止

ios - slider 改变 UIColor 的亮度

ios - 当用户通过语音输入时,应用程序崩溃 uitextview

ios - 使用 ios sdk 进行 Tokbox Api session 记录

ios - UIBarButtonItem 出现在 iPad 模拟器中,但不在实际应用中

ios - 如何创建具有多种单元格类型的分组 TableView ?

ios - 刷新后 UIRefreshControl 未隐藏。 iOS