0

我使用情节提要创建了UIPageViewController四个,但我需要最后一个是. 有一种方法可以添加 或转换为UIViewControllerUINavigationControllerUINavigationControllerUIPageViewControllerUIViewControllerUINavigationController

这是我的代码:

- (void)viewDidLoad
{
  [super viewDidLoad];
   self.dataSource = self ;

  [self setViewControllers:@[self.pagina1]direction:UIPageViewControllerNavigationDirectionReverse animated: YES   completion:nil  ];
UIImageView *backgroundImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"carbon.jpg"]];

  [self.view addSubview:backgroundImage];
  [self.view sendSubviewToBack:backgroundImage];
  // [backgroundImage release];
}




- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];


}


- (ViewControllerPagina1 *) home1 {

    if( !_home1 )
    {
        UIStoryboard *storyboard = self.storyboard ;
        _home1 = [storyboard instantiateViewControllerWithIdentifier:@"Prima pagina"] ;
    }

    return _home1 ;
}

- (ViewControllerPagina2 *) home2 {

    if( !_home2 )
    {
        UIStoryboard *storyboard = self.storyboard ;
        _home2 = [storyboard instantiateViewControllerWithIdentifier:@"Seconda pagina"] ;
    }

    return _home2 ;
}

- (ViewControllerPagina3 *) home3 {

    if( !_home3 )
    {
        UIStoryboard *storyboard = self.storyboard ;
        _home3 = [storyboard instantiateViewControllerWithIdentifier:@"Terza pagina"] ;
    }

    return _home3 ;
}


- (UIViewController *) pageViewController:(UIPageViewController *)pageViewController viewControllerAfterViewController:(UIViewController *)viewController
{
    UIViewController *nextViewController = nil ;

            if( viewController == self.home1 ) nextViewController = self.home2 ;
    else    if( viewController == self.home2 ) nextViewController = self.home3 ;
    else    if( viewController == self.home3 ) nextViewController = self.home1 ;
    return nextViewController ;

}

- (UIViewController *) pageViewController:(UIPageViewController *)pageViewController viewControllerBeforeViewController:(UIViewController *)viewController
{
    UIViewController *nextViewController = nil ;

    if( viewController == self.home1 ) nextViewController = self.pagina3 ;
    else    if( viewController == self.home2 ) nextViewController = self.home1 ;
    else    if( viewController == self.home3 ) nextViewController = self.home2 ;
    return nextViewController ;

}

实际上“home3”是一个UIViewController,我需要把它转换成一个UINavigationController

任何想法?

4

1 回答 1

0

不确定您要在这里做什么。但是,如果您需要在导航控制器中使用视图控制器,请创建导航控制器,将视图控制器添加到它的视图控制器数组中,然后将导航控制器(现在包含视图控制器)添加到您的页面控制器。

我真的不使用故事板。我以编程方式创建我的视图控制器。这很容易做到,我相信它比故事板更灵活。

于 2013-10-28T11:09:42.360 回答