tac*_*cos 38 iphone protocols uiwebview uitableview
我正在使用该方法tableView:indexPathForCell
来实现自定义委托,该委托可以UITableViewCell
根据其UIWebView
内部的框架大小动态调整大小.问题是当我试图找出特定单元格的indexPath是什么时tableView:indexPathForCell
返回nil
:
- (void)trialSummaryTableViewCell:(TrialSummaryTableViewCell *)cell shouldAssignHeight:(CGFloat)newHeight {
NSIndexPath *indexPath = [tableV indexPathForCell:cell];
NSLog(@"tableV: %@\ncell: %@\nindexPath: %@", tableV, cell, indexPath); //<--
// ...
}
Run Code Online (Sandbox Code Playgroud)
这里,tableV
不返回nil
,单元格不返回nil
,但indexPath
返回nil
.
我究竟做错了什么?
编辑:我-(void)trialSummaryTableViewCell
从该tableView:cellForRowAtIndexPath:
方法调用
Jor*_*rez 124
可能是此时细胞不可见.tableView:indexPathForCell在这种情况下返回nil.我使用indexPathForRowAtPoint解决了这个问题,即使单元格不可见,此方法也能正常工作.代码:
UITableViewCell *cell = textField.superview.superview;
NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:cell.center];
Run Code Online (Sandbox Code Playgroud)
Nan*_*r R 13
如果单元格不可见,[tableV indexPathForCell:cell]返回nil.
此外,如果从"cellForRowAtIndexPath"方法调用"trialSummaryTableViewCell",您也可以轻松地将indexPath传递给"trialSummaryTableViewCell"方法.
一个小更新,因为 Jorge Perez 的答案将从 iOS7 开始失败(因为 aUIScrollView
已插入并且呼叫textField.superview.superview
将不再工作)。
NSIndexPath
您可以这样检索:
//find the UITableViewCell superview
UIView *cell = textField;
while (cell && ![cell isKindOfClass:[UITableViewCell class]])
cell = cell.superview;
//use the UITableViewCell superview to get the NSIndexPath
NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:cell.center];
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
18801 次 |
最近记录: |