简体   繁体   English

如何在iOS7上滚动到行?

[英]How to scroll to row on ios7?

I have the following code to select and scroll to a given row in a UITableView: 我有以下代码来选择并滚动到UITableView中的给定行:

-(void) viewWillAppear:(BOOL)inAnimated
{
    NSIndexPath* me = [NSIndexPath indexPathForRow:self.someIndex inSection:0];
    [self.tableView selectRowAtIndexPath:me animated:NO scrollPosition:UITableViewScrollPositionTop];
}

This worked fine in IOS 6 but on IOS 7 the UITableView goes beneath the UITabBar. 这在IOS 6中工作正常,但在IOS 7上,UITableView放在UITabBar下方。

How can I make this code work on IOS 7 and make sure that the row is really visible? 如何使此代码在IOS 7上运行并确保该行真正可见?

Do not use NSIndexPath , instead of NSIndexPath use row number. 不要使用NSIndexPath ,而不是NSIndexPath使用行号。 save the index of row somewhere and use it, In iOS 7 they have changed the structure of index path. 将行的索引保存在某个地方并使用它,在iOS 7中,他们更改了索引路径的结构。 I had the similar issue and resolved it by saving the row instead of NSIndexPath 我有类似的问题,并通过保存行而不是NSIndexPath解决了它

I am guessing that you need to scroll to a point plus the height of the UITab Bar. 我猜您需要滚动到一个点,再加上UITab栏的高度。 You could try changing the offset. 您可以尝试更改偏移量。 (I haven't tried this yet) (我还没有尝试过)

[tableView setContentOffset:CGPointMake(0,tabBar.bounds.size.height) animated:NO];
[tableView setContentInset:UIEdgeInsetsZero];

or maybe it was: 也许是:

[tableView setContentInset:UIEdgeInsetsMake(tabBar.bounds.size.height, 0, 0, 0)];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM