使用cellForRowAtIndexPath从UITableView获取UITableViewCell

Fon*_*nsi 4 uitableview ios

我试图从我的UITableViewController获取一个子类UITableViewCell(类称为'MasterCell'),并改变了IndexPath.让我们说,我将在第一行获得单元格:

NSIndexPath *indexPath = [NSIndexPath indexPathForRow:1 inSection:0];
MasterCell *cell = (MasterCell *)[self.tableView cellForRowAtIndexPath:indexPath];
Run Code Online (Sandbox Code Playgroud)

这发生在我的viewWillAppear方法中.不幸的是,调试时单元格为零.

我有不同的单元格/行,我必须在viewWillAppear方法中更改一些值.你有什么提示吗?

Mar*_*n R 11

[self.tableView cellForRowAtIndexPath:indexPath]返回nil当前不可见的单元格.

您不应使用单元格来存储模型数据,因为向上或向下滚动时会重复使用单元格.