How do I navigate to a specific page programmatically. Basically I have an app with a scrollView populated with a bunch of subviews (tableViews in this case). When clicking on a subview it zooms in and the user can edit and navigate the table, however when I zoom back out I reload the entire view in case there were any changed made by the user. Of course reloading the view sends the user back to page 0. I've tried setting the pageControl.currentpage property but all that does is change the dot of the pageControl. Does that mean that something is wrong or do I need to do something else as well??
All that is controlling the page scrolling is this method:
- (void)scrollViewDidScroll:(UIScrollView *)sender
{
CGFloat pageWidth = self.scrollView.frame.size.width;
int page = floor((self.scrollView.contentOffset.x - pageWidth / 2) / pageWidth) + 1;
self.pageControl.currentPage = page;
NSString *listName = [self.wishLists objectAtIndex:self.pageControl.currentPage];
self.labelListName.text = listName;
}
You have to calculate the corresponding scroll position manually. To scroll to page i:
[scrollView setContentOffset:CGPointMake(scrollView.frame.size.width*i, 0.0f) animated:YES];
来源:https://stackoverflow.com/questions/4185010/navigate-to-specific-page-in-scrollview-with-paging-programmatically