How can I initialize a UITableView so that it starts off showing something (of my choosing) in the middle of the table, rather than what is at the top? I want to have a certain cell in the table always start at the top of the screen, so you could scroll up or down from there.
Share
You can scroll to a certain cell by sending
- (void)scrollToRowAtIndexPath:(NSIndexPath *)indexPath atScrollPosition:(UITableViewScrollPosition)scrollPosition animated:(BOOL)animatedto the table view.As you have described you want the cell of your choosing to appear “in the middle of the table”, so you should use
UITableViewScrollPositionMiddlefor the scrollPosition argument.If you do this as soon right after your table is initialized or as soon as your view loads with the animated argument set to
NOthen the table view will appear with your cell in the middle, just as you’ve described.You also write: “I want to have a certain cell in the table always start at the top of the screen”.
By instead choosing that cell and the scrollPosition
UITableViewScrollPositionTopyou can make that cell be at the top of your table view.