B25Dec
B25Dec

Reputation: 2377

Difference between pagecontrol and pageviewcontroller ios?

What is the difference between UIpageControl and UIpageViewController? What are their use case where these control should used ?

I have created a uipageviewcontroller demo in which i created a pageviewcontroller and for its content i have taken a content view where i am using a image view to change the image on each left or right gesture by user (But haven't used the gesture function for them). When i try to left/right scroll them image just load and disappear and the view which is root view appear.

How can i remove this bug?

Below is the code for the datasource function i have used This is the datasource code that i am using to change the image of the content view:

#pragma mark datasource pagecontroller 

-(UIViewController *)pageViewController:(UIPageViewController *)pageViewController 
     viewControllerBeforeViewController:(UIViewController *)viewController
{
    _currentIndex--;

    if(_currentIndex == 0)
    {
        return nil;
    } else {
        return [self viewControllerAtIndex:_currentIndex];
    }

}

- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController
       viewControllerAfterViewController:(UIViewController *)viewController
{    
    _currentIndex++;

    if(_currentIndex == 4)
    {
        return nil;
    } else {
        return [self viewControllerAtIndex:_currentIndex];
    }
}

- (ContentViewController *)viewControllerAtIndex:(NSUInteger)index
{    
    NSLog(@"~~~~~%lu   %@" ,(unsigned long)index , [NSString stringWithFormat:@"%@",[pageContent objectAtIndex:_currentIndex]]);

    childViewController.imgView.image = [UIImage imageNamed:[NSString stringWithFormat:@"%@",[pageContent objectAtIndex:_currentIndex]]];

    //childViewController.imgView.image = [UIImage imageNamed:@"page3.png"];

    return childViewController;
}

Upvotes: 0

Views: 1764

Answers (2)

Shekhu
Shekhu

Reputation: 2020

UIPageViewController is a class from the UIKit framework that can be used in order to display a collection of UIViewControllers.

Unlike other container classes like UINavigationController or UITabBarController, this class arranges all views either horizontally or vertically in a line.

In order to switch between two screens, users can use the swipe gesture where as the UIPageControl are dots that displays on which page you are on (visible to the user).

Upvotes: 4

Fogmeister
Fogmeister

Reputation: 77651

UIPageViewController is a container controller. It manages the display of several view controllers with scrolling between them.

UIPageControl is the series of little dots that displays which page you are on.

They are completely unrelated to each other. But they can be used together.

As for your "bug" we'll have to see the code in your page view controller datasource. You don't need to use your own gesture recognisers. The page view controller manages the scrolling itself.

EDIT

Your datasource method should look something like this...

- (ContentViewController *)viewControllerAtIndex:(NSUInteger)index {
    MyImageViewController *controller = [MyImageViewController new];

    controller.imgView.image = [UIImage imageNamed:[NSString stringWithFormat:@"%@",[pageContent objectAtIndex:_currentIndex]]];

    return controller;
}

At the moment there seems to be only one controller childViewController. This means that you are trying to create the same one over and over. You need to create new controllers and populate them.

Upvotes: 6

Related Questions