Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Navigate to specific page in scrollView with paging, programmatically

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; } 
like image 414
Glitch Avatar asked Nov 15 '10 13:11

Glitch


1 Answers

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]; 
like image 149
Ole Begemann Avatar answered Sep 24 '22 04:09

Ole Begemann