简体   繁体   中英

How to scroll to row on ios7?

I have the following code to select and scroll to a given row in a 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.

How can I make this code work on IOS 7 and make sure that the row is really visible?

Do not use NSIndexPath , instead of NSIndexPath use row number. save the index of row somewhere and use it, In iOS 7 they have changed the structure of index path. I had the similar issue and resolved it by saving the row instead of NSIndexPath

I am guessing that you need to scroll to a point plus the height of the UITab Bar. 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)];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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