我正在尝试从我的UITableViewController中获取一个子类化的UITableViewCell(类名为'MasterCell'),并且IndexPath是可变的。比如说,我想要获取第一行的单元格:
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:1 inSection:0];
MasterCell *cell = (MasterCell *)[self.tableView cellForRowAtIndexPath:indexPath];
这个问题发生在我的viewWillAppear方法中。不幸的是,在调试时cell为空。
我有不同的单元格/行,我需要在viewWillAppear方法中更改一些值。你有什么提示吗?
nil
的问题可能是由于单元格不可见(如Martin R所提到的),或者因为您的indexPath超出范围(即在您的表格中没有第一部分的第二行)。http://developer.apple.com/library/ios/documentation/uikit/reference/UITableView_Class/Reference/Reference.html#//apple_ref/occ/instm/UITableView/cellForRowAtIndexPath: - gschandler