How to set text on one page and image on another page in UIPageViewController

In my iPad app. I am working on UIPageViewController. I want to set text on one page and image on another page. I've tried and googled a lot but I haven't found any solution. This is killing my time, so if anyone has worked on this please help me and post a sample code.

I used the code that is at the bottom of the link

http://www.ioslearner.com/implementing-uipageviewcontroller-programatically-without-storyboarding/

here is some sample code. I used contentviewcontroller.

I want to use two view controllers with UIPageViewController

- (UIPageViewControllerSpineLocation)pageViewController:(UIPageViewController *)pageViewController
               spineLocationForInterfaceOrientation:(UIInterfaceOrientation)orientation

{

if(UIInterfaceOrientationIsPortrait(orientation))

{
    //Set the array with only 1 view controller
    UIViewController *currentViewController = [self.pageViewController.viewControllers objectAtIndex:0];
    NSArray *viewControllers = [NSArray arrayWithObject:currentViewController];
    [self.pageViewController setViewControllers:viewControllers direction:UIPageViewControllerNavigationDirectionForward animated:YES completion:NULL];

    //Important- Set the doubleSided property to NO.
    self.pageViewController.doubleSided = NO;
    //Return the spine location
    return UIPageViewControllerSpineLocationMin;

}
else
{
    NSArray *viewControllers = nil;
    ContentViewController *currentViewController = [self.pageViewController.viewControllers objectAtIndex:0];

    NSUInteger currentIndex = [self.modelArray indexOfObject:[(ContentViewController *)currentViewController labelContents]];

     NSUInteger currentIndex2 = [self.imagesArray2 indexOfObject:[(ContentViewController *)currentViewController imageContents]];

    if(currentIndex == 0 || currentIndex %2 == 0 || currentIndex2 == 0||currentIndex2 %2 == 0)
    {
        UIViewController *nextViewController = [self pageViewController:self.pageViewController viewControllerAfterViewController:currentViewController];
        viewControllers = [NSArray arrayWithObjects:currentViewController, nextViewController, nil];
    }
    else
    {
        UIViewController *previousViewController = [self pageViewController:self.pageViewController viewControllerBeforeViewController:currentViewController];
        viewControllers = [NSArray arrayWithObjects:previousViewController, currentViewController, nil];
    }
    //Now, set the viewControllers property of UIPageViewController
    [self.pageViewController setViewControllers:viewControllers direction:UIPageViewControllerNavigationDirectionForward animated:YES completion:NULL];

    return UIPageViewControllerSpineLocationMid;
}

      

}

+3


source to share


2 answers


The following steps might be helpful

  • Store UILabel and UIImageView in ContentViewController
  • Add UIImage OR NSString to modelArray.
  • When you create a new ContantViewController, check if the object in the model is an image or a string using the following.
    if ([myObject class] == [UIImage class])
    {
    //HERE ASSIGN IT TO UIIMAGEVIEW.image
    }
    else
    {
    //HERE ASSIGN IT TO UILABEL.text
    }




if you need more help ....

Sorry if this is not what you are looking for .....

0


source


If I understood well, add the image to the ContentPageView.xib file and make an exit. Set ImageView and shortcut to hidden or visible on required pages.



+1


source







All Articles