tableView:indexPathForCell returns nil(tableView:indexPathForCell 返回 nil)
问题描述
I am using the method tableView:indexPathForCell
to implement a custom delegate that can dynamically resize a UITableViewCell
based on the frame size of the UIWebView
that is inside of it. The problem is that tableView:indexPathForCell
is returning nil
when I try to find out what the indexPath of a particular cell is:
- (void)trialSummaryTableViewCell:(TrialSummaryTableViewCell *)cell shouldAssignHeight:(CGFloat)newHeight {
NSIndexPath *indexPath = [tableV indexPathForCell:cell];
NSLog(@"tableV: %@
cell: %@
indexPath: %@", tableV, cell, indexPath); //<--
// ...
}
Here, tableV
does not return nil
, cell does not return nil
, but indexPath
returns nil
.
What am I doing wrong?
Edit: I am calling -(void)trialSummaryTableViewCell
from the tableView:cellForRowAtIndexPath:
method
It could be that the cell is not visible at this moment. tableView:indexPathForCell returns nil in this situation. I solved this using indexPathForRowAtPoint this method works even if the cell is not visible. The code:
UITableViewCell *cell = textField.superview.superview;
NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:cell.center];
这篇关于tableView:indexPathForCell 返回 nil的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:tableView:indexPathForCell 返回 nil


- UITextView 内容插图 2022-01-01
- GPS状态的广播接收器? 2022-01-01
- URL编码Swift iOS 2022-01-01
- 如何在 iPhone 模拟器中重置 NSUserDefaults 数据? 2022-01-01
- 类似于 Mail.app 的 iPad 模态视图控制器? 2022-01-01
- Xcode 7.3 中带有 UILabel 的 UIStackView 2022-01-01
- SetOnItemSelectedListener上的微调程序错误 2022-01-01
- 使用自动布局向 UIScrollView 添加动态大小的视图 2022-01-01
- 网上有没有好的 UIScrollView 教程? 2022-01-01
- 在 Iphone SDK 的导航栏上添加多个按钮 2022-01-01