- [UITableView scrollToRowAtIndexPath:]滚动,但回到第一行 [英] -[UITableView scrollToRowAtIndexPath:] scrolls, but goes back to 1st row

查看:958
本文介绍了 - [UITableView scrollToRowAtIndexPath:]滚动,但回到第一行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个分组表视图,在tableview中有textfields。对于键盘不隐藏文本字段,在textFieldShouldBeginEditing中,我调用scrollToRowAtIndexPath方法,并将正在编辑的行的滚动位置设置为tableview的顶部。



滚动确实发生,但只要键盘出现(即,一旦textFieldShouldBeginEditing返回YES),表滚动回到其原始位置,并显示第一部分的第一行在顶部。我调用scrollToRowAtIndexPath后不调用reloadTable。



问题仅发生在第4行和第5行(bdate和zip)password2



这是我用来滚动到特定行的代码

  if(textField == password2){
indPath = [NSIndexPath indexPathForRow:3 inSection:0];
[self.tableView scrollToRowAtIndexPath:indPath atScrollPosition:UITableViewScrollPositionTop animated:YES];
return YES;
}
else if(textField == bdate){
indPath = [NSIndexPath indexPathForRow:4 inSection:0];
[self.tableView scrollToRowAtIndexPath:indPath atScrollPosition:UITableViewScrollPositionTop animated:YES];
return YES;
}
else if(textField == zip){
indPath = [NSIndexPath indexPathForRow:5 inSection:0];
[self.tableView scrollToRowAtIndexPath:indPath atScrollPosition:UITableViewScrollPositionTop animated:YES];
return YES;
}

有人可以告诉我什么可能会出错?



感谢

解决方案

继续是表视图是橡皮筋回,就像在Safari中的web视图,当你运行通过其边界。最可能的原因是,当弹出键盘时,它在表视图的顶部,但表视图没有物理收缩,因此所有的UITableViewCell适合部分模糊的UITableView,当它们中的一些滚动它的橡皮筋,所以他们都在其内。



为了测试这个尝试减少列表视图的大小,以便你可以看到整个事情当键盘是显示,如果错误消失了,你想编写的代码,动态改变的大小,因为键盘动画和动画。


I have a grouped table view with textfields in the tableview. For the keyboard to not hide the textfields, in the textFieldShouldBeginEditing, I am calling the scrollToRowAtIndexPath method and setting the scroll position of the row being edited to the top of the tableview.

The scrolling does happen, but as soon as the keyboard appears (ie as soon as the textFieldShouldBeginEditing returns YES), the table scrolls back to its original position and displays the first row of the first section on top. I am not calling reloadTable after making a call to scrollToRowAtIndexPath.

The problem occurs only for row 4 and 5 (bdate and zip) password2 works as expected.

This is the code I am using to scroll to a particular row

if(textField == password2){
    indPath = [NSIndexPath indexPathForRow:3 inSection:0];
    [self.tableView scrollToRowAtIndexPath:indPath atScrollPosition:UITableViewScrollPositionTop animated:YES];
    return YES;
}
else if(textField == bdate){
    indPath = [NSIndexPath indexPathForRow:4 inSection:0];
    [self.tableView scrollToRowAtIndexPath:indPath atScrollPosition:UITableViewScrollPositionTop animated:YES];
    return YES;
}
else if(textField == zip){
    indPath = [NSIndexPath indexPathForRow:5 inSection:0];
    [self.tableView scrollToRowAtIndexPath:indPath atScrollPosition:UITableViewScrollPositionTop animated:YES];
    return YES;
}

Can someone please tell me what could be going wrong? Any insight would help.

Thanks

解决方案

I suspect what is going on is that the table view is rubber banding back, just like a webview in Safari does when you run pass its bounds. The most likely reason for this is that when you pop up the keyboard it is on top of the table view, but the table view has not physically contracted, thus all the UITableViewCells fit within the partially obscured UITableView, and when some of them scroll off it rubber bands so they all are within it.

In order to test this try reducing the size of the list view so that you can see the whole thing when the keyboard is displayed, if the bug goes away you want to write code that dynamically changes the size as the keyboard animates in and out.

这篇关于 - [UITableView scrollToRowAtIndexPath:]滚动,但回到第一行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆