我有一段代码,其中委托(delegate)了 UITableView。我想使用表中行的编辑功能。当用户单击一行时,将打开 shouldChangeTextInRange。
通过下面的代码我可以控制行的编辑。这工作正常。
textView.text = ((ANFreeEditCell*)[self.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:[self.tableView indexPathForCell:cell].row inSection:0]]).getTekst;
也有可能编辑了表中的底行之一。在这种情况下,键盘窗口位于表格顶部,self.tableView indexPathForCell:cell].row
返回零行 (0)。
didSelectRowAtIndexPath 从未被调用。
如何访问这些行?
最佳答案
您可以设置表格的内容偏移以使其以编程方式滚动。注册 UIKeyboardDidShowNotification
并滚动表格,以便正在编辑的行不会隐藏在键盘后面。我还没有测试过,但我相信它应该可以工作
希望这对您有所帮助。
考虑西蒙的建议
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didShowKeyBoard:) name:UIKeyboardDidShowNotification object:nil];
-(void)didShowKeyBoard:(NSNotification *)notif
{
float offset = //Value through which you need the tableview to scroll
CGRect cellRect = [self.tableView rectForRowAtIndexPath:_editCellIndexPath];
CGPoint scrollPoint = CGPointMake(0.0, cellRect.origin.y - (offset-self.tableView.contentOffset.y));
[self.tableView setContentOffset:scrollPoint animated:YES];
}
关于ios - 隐藏行的当前行委托(delegate) UITableView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21089639/