iphone - TableView :indexPathForCell returns nil

标签 iphone uitableview uiwebview protocols

我正在使用方法 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/

相关文章:

ios - iAD 未按预期工作

ios - 无法从 weather-api 获取 json。 iOS

ios - 程序收到信号 : EXC_BAD_ACCESS

ios - 在UIWebView中拦截图像中的链接

ios - 如果另一台设备已响应警报,则删除推送通知警报

iphone - 如何禁用 UITableView 的单个单元格的选择?

ios - 如何在 TableView Cell 中创建长按按钮以进行 segue

ios - UIWebView 具有授权,单击链接时使用相同的身份验证

javascript - 是否可以调用将值返回给 javascript 的 Objective-C 函数?

iphone - UI 对象 -> 核心数据关联(子类化 UIButton,添加实例变量)