使用cellForRowAtIndexPath从UITableView获取UITableViewCell

我想从一个变化的IndexPath从我的UITableViewController获得一个子类UITableViewCell(类被称为“MasterCell”)。 比方说,我会在第一行获取单元格:

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

这发生在我的viewWillAppear方法。 不幸的是,debugging时单元是零。

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

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

您不应该使用单元格来存储模型数据,因为在向上或向下滚动时单元格将被重新使用。