SRMR SRMR - 6 months ago 13
Objective-C Question

Start TableView at specific index path row

I have a a

tableView
that I want to show on screen at a specific
indexPath.row
.

For example, say each
tableViewCell
takes up half of the screen, and I want the screen to appear at
indexPath.row
of 6, instead of always starting at
indexPath.row
of 0
.

Is there any way to do this?

To make clearer, I want to have the table view appear scrolled such that rows 0-5 are scrolled off-screen, and row 6 is the top row in the table view.

Answer

You can use scrollToRowAtIndexPath:

NSIndexPath *indexPath = [NSIndexPath indexPathForRow:N inSection:M];
    [yourTableView scrollToRowAtIndexPath:indexPath 
                         atScrollPosition:UITableViewScrollPositionTop 
                                 animated:YES];

You can experiment with these positions until you are happy with the results

UITableViewScrollPositionNone
UITableViewScrollPositionTop
UITableViewScrollPositionMiddle
UITableViewScrollPositionBottom