滚动到选定的表格单元格
我实现了一个 TableView 以在选择特定行时显示 PickerView。但这有时会阻止选定的单元格。所以,我希望当 pickerView 显示时我的scrollView 滚动到选定的单元格。
有没有办法获取所选行的当前位置?这样我就可以实现像
//---scroll to the current text field---
CGRect textFieldRect = [currentTextField frame];
[scrollView scrollRectToVisible:textFieldRect animated:YES];
“谢谢”这样的东西。
I implemented a TableView to show up a PickerView when a particular row is selected. But that would sometime block the selected cell. So, I want my scrollView to scroll to the selected cell when the pickerView shows up.
Is there anyway to get the current location of the selected row? Such that I can implement something like
//---scroll to the current text field---
CGRect textFieldRect = [currentTextField frame];
[scrollView scrollRectToVisible:textFieldRect animated:YES];
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果你想解决pickerView或者键盘隐藏屏幕的问题,可以尝试这种方法。实现
heightForFooterInSection
并设置一个高度值,tableView 将向上滚动到您指定的相同值。如果您只想让 tableView 滚动,只需实现
scrollToRowAtIndexPath:atScrollPosition:animated:
Edit:
由于您使用的是
UIScrollView
,您可以使用编程方式滚动到某个区域另请阅读此参考:http://www.aaron.griffith.name/ weblog/2011/02/23/scrolling-a-uiscrollview-programmatically/
If you want to solve the pickerView or the keyboard hiding the screen, you can try this approach. Implement the
heightForFooterInSection
and set a height value, and the tableView will scroll up to the same value as you specify there.If you just want the tableView to scroll , just implement the
scrollToRowAtIndexPath:atScrollPosition:animated:
Edit:
Since you are using a
UIScrollView
, you can programmatically scroll to a certain region usingAlso read through this reference: http://www.aaron.griffith.name/weblog/2011/02/23/scrolling-a-uiscrollview-programmatically/