UIPageViewController iOS 的下一页按钮

Posted

技术标签:

【中文标题】UIPageViewController iOS 的下一页按钮【英文标题】:Next Page Button for UIPageViewController iOS 【发布时间】:2014-10-08 08:34:50 【问题描述】:

我跟着 http://www.appcoda.com/uipageviewcontroller-storyboard-tutorial/ 创建了一个 PageViewController。

本教程包含: (重启按钮的代码)

- (IBAction)restartButton:(id)sender 
PageContentViewController *startingViewController = [self viewControllerAtIndex:0];
NSArray *viewControllers = @[startingViewController];
[self.pageViewController setViewControllers:viewControllers   direction:UIPageViewControllerNavigationDirectionReverse animated:NO completion:nil];

当我尝试像这样的 下一步 按钮时:

- (IBAction)nextPageButton:(id)sender 
PageContentViewController *startingViewController = [self viewControllerAtIndex:+1];
NSArray *viewControllers = @[startingViewController];
[self.pageViewController setViewControllers:viewControllers   direction:UIPageViewControllerNavigationDirectionReverse animated:NO completion:nil];

但它失败了,如何使用 UIButton 执行下一页操作,该 UIButton 以 PageControl 响应直到最后一页。

【问题讨论】:

***.com/questions/7208871/… 最新答案可能会有所帮助 【参考方案1】:

这不起作用,因为您使用的是 +1,请尝试以下操作:

//get current index of current page
DataViewController *theCurrentViewController = [self.pageViewController.viewControllers objectAtIndex:0];
NSUInteger retreivedIndex = [self.modelController indexOfViewController:theCurrentViewController];

//check that current page isn't first page
if (retreivedIndex < 5)

    //get the page to go to
    DataViewController *targetPageViewController = [self.modelController viewControllerAtIndex:(retreivedIndex + 1) storyboard:self.storyboard];

    //put it(or them if in landscape view) in an array
    NSArray *theViewControllers = nil;    
    theViewControllers = [NSArray arrayWithObjects:targetPageViewController, nil];

    //add page view
    [self.pageViewController setViewControllers:theViewControllers direction:UIPageViewControllerNavigationDirectionForward animated:YES completion:NULL];


【讨论】:

那个modelController是什么意思?【参考方案2】:
PageNumberToJump=2


-(void)buyAction


isFromBuy = YES;

    APPChildViewController *initialViewController = [self viewControllerAtIndex:PageNumberToJump];
    viewControllers = [NSArray arrayWithObject:initialViewController];
    [self.pageController setViewControllers:viewControllers direction:UIPageViewControllerNavigationDirectionForward animated:NO completion:nil];


-(NSInteger)presentationIndexForPageViewController:(UIPageViewController *)pageViewController


    if (isFromBuy)
    
        isFromBuy = NO;
        return PageNumberToJump;
    
    return 0;


【讨论】:

以上是关于UIPageViewController iOS 的下一页按钮的主要内容,如果未能解决你的问题,请参考以下文章

IOS 如何从其子级访问 uipageviewcontroller?

访问iOS6 UIPageViewController 创建的UIPageControl?

iOS UIPageViewController

iOS - 这是由 UISegmentedControl 控制的 UIPageViewController,还是这是啥?

UIPageViewController 让 UItalkeViewController 在 iOS 13 上“跳跃”

iOS Swift:UIPageViewController - 以编程方式翻页