UIPageControl loads a new view or another controller

I just "tried" to list apple lessons using PageControl. Now I have to point out that I did not quite understand this, it seemed complicated, so I apologize if this question is very obvious.

I noticed that the apple downloaded its contents from .plist. Now everything is good and easy if all you have is one UILabel and UIImageView, but what if I do something more complicated? What if I want each "page" to have 14 different variables, a button on each "page" that does something else depending on which page you ...

So my question is this (maybe it would be unwise to do it first): Is there a way to encode it when the user switches to the page, loads another controller that has its own .Xib file and view already created in the interface builder?

thanks

+4
source share
1 answer

Yes there is. You must use the UIPageViewController . The UIPageViewController has a data source and delegation methods that are invoked depending on whether the user moves left or right. Basically he says: "Hey, give me a UIViewController, which should be displayed before or after this UIViewController."

Here is an example:

MyPageViewController.h

 @interface MyPageViewController : UIPageViewController <UIPageViewControllerDataSource, UIPageViewControllerDelegate> @end 

MyPageViewController.m

 #import "MyPageViewController.h" @implementation MyPageViewController - (id)init { self = [self initWithTransitionStyle:UIPageViewControllerTransitionStyleScroll navigationOrientation:UIPageViewControllerNavigationOrientationHorizontal options:nil]; if (self) { self.dataSource = self; self.delegate = self; self.title = @"Some title"; // set the initial view controller [self setViewControllers:@[[[SomeViewController alloc] init]] direction:UIPageViewControllerNavigationDirectionForward animated:NO completion:NULL]; } return self; } #pragma mark - UIPageViewController DataSource methods - (UIViewController *)pageViewController:(UIPageViewController *)pvc viewControllerBeforeViewController:(UIViewController *)vc { // here you put some logic to determine which view controller to return. // You either init the view controller here or return one that you are holding on to // in a variable or array or something. // When you are "at the end", return nil return nil; } - (UIViewController *)pageViewController:(UIPageViewController *)pvc viewControllerAfterViewController:(UIViewController *)vc { // here you put some logic to determine which view controller to return. // You either init the view controller here or return one that you are holding on to // in a variable or array or something. // When you are "at the end", return nil return nil; } @end 

What is it!

0
source

Source: https://habr.com/ru/post/1385034/


All Articles