来自 UIPageViewController 的导航控制器 pushViewController 不起作用

navigationController pushViewController from UIPageViewController not work

我是 iOS 开发的新手。 我有一个带有导航控制器的故事板,UIViewController 连接到它。

UIViewController自定义class中我在UIPageViewController下添加三个UIViewController:

_one= [self.storyboard instantiateViewControllerWithIdentifier:@"View1"];
_two = [self.storyboard instantiateViewControllerWithIdentifier:@"View2"];
_three = [self.storyboard instantiateViewControllerWithIdentifier:@"View3"];   
_page = [[CustomUIPageViewController alloc] initWithParentViewController:self];
_page.viewControllers = @[_one, _two, _three];
[self.view addSubview:_page.view];
...

我想通过调用此代码显示第 _two 页的视图:

ResultViewController *view = [self.storyboard instantiateViewControllerWithIdentifier:@"ResultBoard"];
        [self.navigationController pushViewController:view animated:YES];

但是不行,我也试试:

[self.parentViewController.navigationController pushViewController:view animated:YES];

我现在可以解决我的问题了。这不是 "clean" 方式,但它有效。 在 _two 控制器上,我添加:

@property (weak, nonatomic) UINavigationController *navigationCustomController;

然后在初始化时添加:

_two.navigationCustomController = self.navigationController;

之后我就打电话给:

ResultViewController *view = [self.storyboard instantiateViewControllerWithIdentifier:@"ResultBoard"];
[_navigationCustomController pushViewController:view animated:YES];

而且有效。