views:

31

answers:

1

I have a grouped UITableView that has basic data inside it, but I would like to start the UITableView at a certain section when the app loads, can this be achieved?

Thanks Mark

+1  A: 

Sure - use the scrollToRowAtIndexPath method of UITableView. Using the index path you specify which section and which row you would like to scroll to. Presumably you would like to see it at the top of the table so in the method call specify UITableViewScrollPositionTop.

Adam Eberbach
cool, thanks, but *when* do I call this? Im a little confused as to where in the loading lifecycle this code should be called?
Mark
viewWillAppear: (in the view controller managing your table view) would be a good time if you want to start the table view at a certain point when the view appears.
Adam Eberbach
I get the error: `-[UITableView scrollToRowAtIndexPath:atScrollPosition:animated:]: section (1) beyond bounds (0).` but can assure you my table has 3 sections. Are you sure `viewWillAppear` is the right place?
Mark
here is my code: `[tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection: 1] atScrollPosition:UITableViewScrollPositionTop animated:YES];`
Mark
it should work if you explicitly do [tableView reloadData]; before the scroll - unless the table is loaded the section you want to go to may not exist.
Adam Eberbach
thanks that got it!
Mark