UIPageViewController(ScrollStyle)不调用dataSource方法

时间:2014-06-18 20:04:37

标签: ios uiviewcontroller navigation uikit uipageviewcontroller

我想我不清楚手势如何与UIPageViewController一起使用。我尝试使用四种不同的屏幕设置应用程序"并决定UIPageviewController将是一种促进它们之间滑动的好方法。这是我执行设置的方法

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[self setWorldWalkViewController:[EGLWorldWalkViewController new]]; //One of the content views

[self setPageView:[[UIPageViewController alloc]initWithTransitionStyle:UIPageViewControllerTransitionStyleScroll 
navigationOrientation:UIPageViewControllerNavigationOrientationHorizontal options:nil]];

[self.pageView setViewControllers:@[self.worldWalkViewController,]//Sets the initial view to display, I think.
direction:UIPageViewControllerNavigationDirectionForward animated:YES completion:nil];

[self.pageView setDelegate:self];
[self.pageView setDataSource:self];

self.window = [[UIWindow alloc]init];
[self.window setRootViewController:self.pageView];

currentView = WorldWalk; //Where WorldWalk is an enum value
[self.window makeKeyAndVisible];

return YES;
}
嗯......我希望这不会太久。无论如何这里是dataSource方法:

-(UIViewController *)pageViewController:(UIPageViewController *)pageViewController 
viewControllerAfterViewController:(UIViewController *)viewController{
currentView += 1;
switch (currentView) {
    case WorldWalk:
        return [[EGLWorldWalkViewController alloc]init];
        break;
    case MonthlyMarch:
    //There is more but this method isn't even being called so…

我知道我在这里做错了一些辅助事情(就像把所有这些东西放在didFinishLaunching中:)但是现在我真正专注于弄清楚如何让导航工作。 (概念验证阶段。)

值得注意的两件事:

  1. 该应用专为景观设计(此时)
  2. 我没有使用Storyboard,但每个自定义视图控制器都有自己的XIB
  3. 该文档似乎表明pageViewController具有映射出的导航内容并且它只需要数据,但是当我单击并拖动时没有任何反应。我的dataSource方法甚至没有被调用,文档很薄,我觉得我错过了什么,所以也许有人可以启发我?

1 个答案:

答案 0 :(得分:5)

这个问题对我来说是因为我没有保留页面视图控制器。确保你对它有强烈的引用,并且应该调用这些方法。