我想我不清楚手势如何与 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 中:)但现在我真的专注于弄清楚如何让导航工作。 (概念验证阶段。)
有两点值得注意:
该文档似乎表明 pageViewController 已映射出导航内容并且它只需要数据,但是当我单击并拖动时没有任何 react 。我的 dataSource 方法甚至没有被调用,这里的文档很薄,我觉得我遗漏了一些东西,所以也许有人可以启发我?
最佳答案
这个问题发生在我身上,因为我没有保留页面 View Controller 。确保对它保持强烈的引用,并且应该调用方法。
关于ios - UIPageViewController (ScrollStyle) 不调用 dataSource 方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24294138/