简体   繁体   中英

UITableView Can't scroll to last Row

I have a table view set up with a couple of different rows where each row contains two UITextViews. When the user starts editing a text view I want that table view cell where its located to be scrolled to the top of the table view. To scroll I am using:

[self.tableView scrollToRowAtIndexPath:indexPath
                          atScrollPosition:UITableViewScrollPositionTop
                                  animated:YES];

This is working fine except for the last two rows, where the row is scrolled a little bit but not all the way to the top.

I think the issue is that the content size of the table view is not large enough to allow scrolling but I don't know how to adjust it in a proper way.

Any help would be appreciated.

Thanks in Advance!

Just call this method in viewDidLoad and your problem will get solved.

- (void)configureInsetsOfTableView
{
    CGFloat defaultSpacing=10.0f;

    [self.tableView setContentInset: UIEdgeInsetsMake(0.f, 0.f,   self.navigationController.navigationBar.bounds.size.height + [UIApplication sharedApplication].statusBarFrame.size.height +defaultSpacing, 0.f)];
    [self.tableView setScrollIndicatorInsets:UIEdgeInsetsMake(0.f, 0.f, self.navigationController.navigationBar.bounds.size.height +    [UIApplication sharedApplication].statusBarFrame.size.height +defaultSpacing, 0.f)];
}

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