我正在使用方法 tableView:indexPathForCell
来实现自定义委托(delegate),该委托(delegate)可以根据 UIWebView
的帧大小动态调整 UITableViewCell
的大小> 那是在它里面。问题是,当我尝试找出特定单元格的 indexPath 时,tableView:indexPathForCell
返回 nil
:
- (void)trialSummaryTableViewCell:(TrialSummaryTableViewCell *)cell shouldAssignHeight:(CGFloat)newHeight {
NSIndexPath *indexPath = [tableV indexPathForCell:cell];
NSLog(@"tableV: %@\ncell: %@\nindexPath: %@", tableV, cell, indexPath); //<--
// ...
}
这里,tableV
不返回nil
,cell不返回nil
,但是indexPath
返回无
。
我做错了什么?
编辑:我正在从 tableView:cellForRowAtIndexPath:
方法调用 -(void)trialSummaryTableViewCell
最佳答案
此时该单元格可能不可见。 tableView:indexPathForCell 在这种情况下返回 nil。我使用 indexPathForRowAtPoint 解决了这个问题,即使单元格不可见,该方法也可以工作。代码:
UITableViewCell *cell = textField.superview.superview;
NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:cell.center];
关于iphone - TableView :indexPathForCell returns nil,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6930026/