Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • PageViewController

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 347
    Comment on it

    Hi Guys,

    Do you know how to implement PageViewController ?
    This is an IOS very good and efficient feature. Below I have implemented a example which will help you use the PageViewController.
    Lets assume you have create a Book for kids which helps them learn Alphabet of English Language.

    Create a New View Controller.

    **PageView.h**
    #import <UIKit/UIKit.h>
    
    @interface PageView : UIViewController<UIPageViewControllerDataSource,UIPageViewControllerDelegate>
    @end
    
    
    **PageView.m**
    
    - (void)viewDidLoad
    {
        [super viewDidLoad];
    
        self.pageController = [[UIPageViewController alloc] 
    initWithTransitionStyle:UIPageViewControllerTransitionStylePageCurl
                                                              navigationOrientation:UIPageViewControllerNavigationOrientationHorizontal options:nil];
    // above line helps us provide animation to page View Contoller . You can also add simple Scroll instead of 
    //Page curl .     
        self.pageController.dataSource = self;
        [[self.pageController view] setFrame:[[self view] bounds]];
        NSLog(@"value of page is%d",self.page);
    //View Controller you want to show on page View
        ExampleViewController *exampleViewController = [self viewControllerAtIndex:self.page];
        NSArray *viewControllers = [NSArray arrayWithObject:exampleViewController];
    
        [self.pageController setViewControllers:viewControllers direction:UIPageViewControllerNavigationDirectionForward animated:NO completion:nil];
    
        [self addChildViewController:self.pageController];
        [[self view] addSubview:[self.pageController view]];
        [self.pageController didMoveToParentViewController:self];
    
    
    }
    
    // these are pageVIew Delegate methods which will controll your left and right swipe.  
    
    - (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerBeforeViewController:(UIViewController *)viewController {
    
        NSUInteger index = [(ExampleViewController *)viewController index];
    
        if (index == 0) {
    
            return nil;
        }
    
        index--;
    
        return [self viewControllerAtIndex:index];
    
    }
    
    - (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerAfterViewController:(UIViewController *)viewController {
    
        NSUInteger index = [(ExampleViewController *)viewController index];
        index++;
    
        if (index == 10) {
            // you can extend it upto your array count. 
    }
               return [self viewControllerAtIndex:index];
    } 
    
    - (ExampleViewController *)viewControllerAtIndex:(NSUInteger)index {
    
        ExampleViewController *exampleViewController = [[ExampleViewController alloc] initWithNibName:@"ExampleViewController" bundle:nil];
    
    /// Pass array and its content to detail page 
    
        if (index>=arrayCount) {
            return nil;
        }else
        {
            return exampleViewController;
        }
    
    }
    

    Make app easy with this functionality.

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: