gpt4 book ai didi

ios - 带有 ViewController 的 PageViewController

转载 作者:行者123 更新时间:2023-12-01 17:55:58 24 4
gpt4 key购买 nike

我找不到将 View Controller 作为页面的 PageViewController 的工作示例。

我只需要两个水平 View Controller :viewcontroller1 和 viewcontroller2。

这是我的viewDidLoad:

- (void)viewDidLoad {
[super viewDidLoad];
self.pageController = [[UIPageViewController alloc] initWithTransitionStyle:UIPageViewControllerTransitionStyleScroll navigationOrientation:UIPageViewControllerNavigationOrientationVertical options:nil];

self.pageController.dataSource = self;
[[self.pageController view] setFrame:[[self view] bounds]];

storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard_iPhone" bundle: nil];
controller1 = [storyboard instantiateViewControllerWithIdentifier:@"first"];
controller2 = [storyboard instantiateViewControllerWithIdentifier:@"second"];

viewControllers = [NSArray arrayWithObjects:controller1, nil];

[self.pageController setViewControllers:viewControllers direction:UIPageViewControllerNavigationDirectionForward animated:NO completion:nil];

[self addChildViewController:self.pageController];
[[self view] addSubview:[self.pageController view]];
[self.pageController didMoveToParentViewController:self];
}


- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerBeforeViewController:(UIViewController *)viewController {
return controller1;
}

- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerAfterViewController:(UIViewController *)viewController {
return controller2;
}

问题是,在滑动第二个 View 后,它就消失了。
一些帮助理解 PageViewController 会非常好。

提前致谢

最佳答案

像这样更改您的委托(delegate)方法,它应该可以正常工作:

- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerBeforeViewController:(UIViewController *)viewController {
if (self.pageController.viewControllers[0] == self.controller2)
return self.controller1;
return nil;
}

- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerAfterViewController:(UIViewController *)viewController {
if (self.pageController.viewControllers[0] == self.controller1)
return self.controller2;
return nil;
}

关于ios - 带有 ViewController 的 PageViewController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17617294/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com