CustomTableCell * cell = [self.tableView cellForRowAtIndexPath:indexPath];
偶尔会返回nil,原因在于:An object representing a cell of the table, or nil if the cell is not visible or indexPath is out of range.所以当你的 cell 是不可见的时候就会返回nil
解决方法:重新获取
CustomTableCell * cell = [self.tableView cellForRowAtIndexPath:indexPath];
if (indexPath) {
//定于到该行cell(此方法可以用于解决cell被遮挡的问题)
[self.tableView scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionBottom animated:YES];
}
if (cell) {
[NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(indexPathForCell:) object:nil];
}else{
[self performSelector:@selector(indexPathForCell:) withObject:indexPath afterDelay:.5];
}
- (void)indexPathForCell:(id)object {
if ([object isKindOfClass:[NSIndexPath class]]) {
NSIndexPath * indexPath = (NSIndexPath *)object;
CustomTableCell * cell = [self.tableView cellForRowAtIndexPath:indexPath];
}
}
网友评论