ios - 隐藏行的当前行委托(delegate) UITableView

标签 ios objective-c xcode uitableview

我有一段代码,其中委托(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/

相关文章:

ios - 异步更新 UI 的正确方法是什么?

ios - 我们可以通过多少种方式访问​​ iOS 用户的位置?

ios - 如何用swift 2.0播放背景音乐?

iOS。字体在模拟器上可用,但在设备上不可用

ios - 尝试使用枚举过滤值时出现模棱两可的错误

ios - 如何知道 View 层次结构中是否显示 UIActionSheet?

ios - 如何在 iOS 中单击按钮时在 hidden=YES 和 hidden=NO 之间切换?

ios - Amazon S3 uploadPart 返回 null

ios - 在 Swift Xcode 中以编程方式下拉列表菜单

objective-c - 如何在LLDB中打印具有给定地址的对象的属性?