我有一个表格 View ,其中包含使用 autolayout
构造的动态单元格。我在 UITableViewCell 中有一个 UITextView
作为 subview 。此 UITextView
可以垂直增长,即此 TextView 禁用滚动,并且其高度约束等于单元格内容 View 的高度。因此,每当 textview 高度增加时,相应单元格的高度也会增加。
我需要获取任何给定单元格的索引路径。
当 textview 高度变得高于屏幕高度时,indexPathForCell
返回 nil。我也试过 indexPathForRowAtPoint:[cell center]
它也返回 nil。我无法从我的模型单元格数组中获取索引路径,因为模型没有我的单元格(单元格已从模型数组中删除)。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
NSMutableArray *cellArray = [tableViewCellsDictionary objectForKey:[NSNumber numberWithUnsignedLong:sectionIndex]];
return [cellArray objectAtIndex:rowIndex];
}
-(void) updateTextViewTextInCell:(CustomCell *) cell {
NSIndexPath *currentCellIndexPath1 = [tableView indexPathForCell:cell]; // Returns nil
NSIndexPath *currentCellIndexPath2 = [tableView indexPathForRowAtPoint:[cell center]]; // Returns nil
}
我从 textViewDidEndEditing
调用此 updateCellTextView
方法,以将 TextView 的文本保存在我的模型中。
但我无法获取单元格的索引路径。
如何在这种情况下获取单元格的索引路径,即当单元格完全超出屏幕时。
最佳答案
如果你想在textViewDidEndEditing
中获取单元格的indexpath
,你可以使用此代码。
CGPoint point = [textView convertPoint:CGPointZero toView:self.tableview];
NSIndexPath *indexPath = [self.tableview indexPathForRowAtPoint:point];
关于ios - 无法获取 UITableViewCell 的索引路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41457601/