I want to scroll or move to another views. How to do that with use of page control?
Asked
Active
Viewed 1,622 times
1
-
2Did you check that http://stackoverflow.com/questions/29074454/how-to-create-a-scroll-view-with-a-page-control-using-swift?rq=1 – Amanpreet Dec 28 '16 at 09:11
-
i am using objective c. thanks – aditya Dec 28 '16 at 09:12
-
i want to move completely to another view controller, not just change the colour of the view. – aditya Dec 28 '16 at 09:17
-
May this will helps you http://stackoverflow.com/questions/10198732/programmatically-linking-uipagecontrol-to-uiscrollview and http://www.iostutorialjunction.com/2015/05/uipagecontrol-tutorial-ios-objective-c.html – Amanpreet Dec 28 '16 at 09:25
-
Just so that I'm clear, you are using `UIPageViewController` to change your `UIViewControllers`? and `UIPageControl` to just show the current page, right? – Rikh Dec 28 '16 at 10:03
-
thanks Rikh, yes i am using page viewcontroller to change my views, but the problem is how to connect this page view controller to them on the storyboard...should i have to write the delegate code in each view controller? – aditya Dec 29 '16 at 06:48
-
@Amanpreet thanks friend for those 2 links, but i need storyboard connections(how to connect them or link between view controllers and page view controller)...in the second link they are just changing the colour of the scrollview which i don't want exactly, i want to completely navigate to the next page where i can see the selected page as well as my new page contents – aditya Dec 29 '16 at 06:54
3 Answers
0
the system provides UIPageViewController,you can use it and UIPageControl to obtain what you think

looking privacy
- 41
- 8
-
thanks asdemon. but i need code how to use 2 or many different view controllers. many websites and youtube videos showed how to change colour in the same window with different page control options. But in my case i want to completely move to new view controller – aditya Dec 28 '16 at 09:16
-
The UIPageViewController plays a role of container, Your different view controllers can put into it and use it to navigation between them. – looking privacy Dec 29 '16 at 02:00
-
how to put the view controllers into page view controller...or how to add my buttons and other elements in the page view controller....should i have to add 3 page view controllers for 3 different views? – aditya Dec 29 '16 at 06:45
-
This tutorial may help you: http://www.theappguruz.com/blog/uipageviewcontroller-in-ios – looking privacy Dec 29 '16 at 09:27
-
thanks again, this website again one of those who showed how to change the colour and image, they are not navigating to the other view controllers...because there is only one view controller – aditya Dec 30 '16 at 05:25
0
You can use pageControl's property currentPage
@property(nonatomic) NSInteger currentPage; // default is 0. value pinned to 0..numberOfPages-1
It can be used as
[pageControl setCurrentPage:<logic to get your VC>];

iYoung
- 3,596
- 3
- 32
- 59
-
thanks iYoung. but i need full code and storyboard connection to understand it – aditya Dec 29 '16 at 06:46
-
buddy just a suggestion. This site is just to help with the issues you are facing in your implementation & not telling the complete flow with the complete logic & storyboard. You need to learn to help yourself with some suggestions. – iYoung Dec 29 '16 at 06:52
-
thanks @iyoung, but the problem is there are several websites/videos which are showing how to use page view controllers, but 80% of them are just changing a scroll view portion of a single view controller, other 20% are using swift language. In my case there are 3 different view controllers and my language is objective c. So i require code and storyboard connections/links of page view and 3 different view controllers. – aditya Dec 29 '16 at 06:59
0
pages is an array where you will store storyboard id's and NSInteger currentPageIndex, set currentPageIndex = 0
- (void)viewDidLoad
{
self.pages = [[NSMutableArray alloc]init];
// instantiate the view controlles from the storyboard
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
UIViewController* ViewController1 = [storyboard instantiateViewControllerWithIdentifier:@"VC1"];
UIViewController* ViewController2 = [storyboard instantiateViewControllerWithIdentifier:@"VC2"];
// load the view controllers in our pages array
[self.pages addObjectsFromArray:@[ViewController1, ViewController2]];
// your general suff
}
- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerBeforeViewController:(UIViewController *)viewController {
NSInteger index = [_pages indexOfObject:viewController];
if ((index == NSNotFound) || (index == 0)) {
return nil;
}
index--;
return [_pages objectAtIndex:index];
}
- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerAfterViewController:(UIViewController *)viewController {
NSInteger index = [_pages indexOfObject:viewController];
if (index == NSNotFound) {
return nil;
}
index++;
if (index == [_pages count]) {
return nil;
}
return [_pages objectAtIndex:index];
}
-(void)pageViewController:(UIPageViewController *)pageViewController didFinishAnimating:(BOOL)finished previousViewControllers:(NSArray *)previousViewControllers transitionCompleted:(BOOL)completed {
if (completed) {
self.currentPageIndex = [_pages indexOfObject:[pageViewController.viewControllers lastObject]];
}
}

Arjun Ker
- 11
- 4
-
should i have to add UIPageViewControllerDelegate? and how to do this on storyboard... i have added one pageviewcontroller...but how to link this page view with the three views on storyboard. – aditya Dec 29 '16 at 06:43
-
add the above code in class that you had assign to your PageViewController, and yes you need to add delegate for it. – Arjun Ker Dec 30 '16 at 05:59