我已经使用 UIPageViewController 在 webview 中加载大约 5 个图像。所以每当下面的代码行
- (UIViewController *)pageViewController:(UIPageViewController *) pageViewController viewControllerBeforeViewController:(UIViewController *)viewController
, 被调用,返回对象是一个类对象(在我的例子中,类名是 LoadPage)。在我的代码中一切正常,但我在这里遇到了一些奇怪的问题并且有点不舒服。
所以我计划搬到一个班级而不是两个班级。
现在这个方法的返回类型将是 self。
- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerAfterViewController:(UIViewController *)viewController
{
return self;
}
我对吗?
但是当我尝试初始化 UIPageViewController 时,应用程序在某一行崩溃了。
- (void) createViewControllers {
self.pageViewController = [[UIPageViewController alloc] initWithTransitionStyle:UIPageViewControllerTransitionStylePageCurl navigationOrientation:UIPageViewControllerNavigationOrientationHorizontal options: nil];
pageViewController.delegate = self;
pageViewController.dataSource = self;
NSArray* nextScreens = [NSArray arrayWithObject:self];
[pageViewController setViewControllers: nextScreens direction:UIPageViewControllerNavigationDirectionForward animated:NO completion:nil];
[self addChildViewController:pageViewController];
[self.view addSubview:pageViewController.view];
[[self view] addSubview:[pageViewController view]]; //CRASH
[pageController didMoveToParentViewController:self];
CGRect pageViewRect = self.view.bounds;
pageViewRect = CGRectInset(pageViewRect,0, 0);
pageViewController.view.frame = pageViewRect;
self.view.gestureRecognizers = pageViewController.gestureRecognizers;
}