使用按钮移动pageViewController(objective-c)

时间:2015-10-16 19:24:06

标签: ios objective-c uipageviewcontroller

我有一个pageViewController,每次滑动都会在屏幕上显示不同的图像。分页工作与手势很好。但是,我正在尝试实现一个按钮来执行分页。我左上方有一个按钮叫"返回"右上角的按钮称为"下一个"。我无法使这些按钮起作用。

注意:OnboardingChildViewController是LoginSignUpController的子控制器

代码
LoginSignUpViewController.m:

#pragma mark - Paging delegate

- (OnboardingChildViewController *)viewControllerAtIndex:(NSUInteger)index {

    OnboardingChildViewController *childViewController = [[OnboardingChildViewController alloc] initWithNibName:@"OnboardingChildViewController" bundle:nil];
    childViewController.index = index;
    return childViewController;

}

- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerBeforeViewController:(UIViewController *)viewController {

    NSUInteger index = [(OnboardingChildViewController *)viewController index];

    if (index == 0) {
        return nil;
    }

    // Decrease the index by 1 to return
    index--;

    return [self viewControllerAtIndex:index];

}

- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerAfterViewController:(UIViewController *)viewController {

    NSUInteger index = [(OnboardingChildViewController *)viewController index];

    index++;

    if (index == 5) {
        return nil;
    }

    return [self viewControllerAtIndex:index];

}

- (NSInteger)presentationCountForPageViewController:(UIPageViewController *)pageViewController {
// The number of items reflected in the page indicator.
return 5;
}

- (NSInteger)presentationIndexForPageViewController:(UIPageViewController *)pageViewController {
// The selected item reflected in the page indicator.
return 0;
}

OnboardingChildViewController.m:

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor clearColor];

    switch(self.index)
    {
    case 0: {
        self.dismissButton.hidden = true;
        self.onboardingImage.image = nil;
        [self.nextButton setTitle:@"Take a Tour" forState:UIControlStateNormal];
        self.onboardingDescription.hidden = true;
        self.index = 0;
        break;
    }
    case 1: {
        self.dismissButton.hidden = false;
        self.onboardingImage.image = [UIImage imageNamed: @"onboardingImage1.png"];
        self.onboardingDescription.text = @"Follow users to see their content in your feed";
        self.index = 1;
        break;
    }
    case 2: {
        self.dismissButton.hidden = false;
        self.onboardingImage.image = [UIImage imageNamed: @"onboardingImage2.png"];
        self.onboardingDescription.text = @"Listen to Stations based on your interest";
        self.index = 2;
        break;
    }
    case 3: {
        self.dismissButton.hidden = false;
        self.onboardingImage.image = [UIImage imageNamed: @"onboardingImage3.png"];
        self.onboardingDescription.text = @"Easily Search for Users, Posts, and Stations";
        self.index = 3;
        break;
    }
    default: {
         self.dismissButton.hidden = false;
        self.onboardingImage.image = [UIImage imageNamed: @"onboardingImage4.png"];
        [self.nextButton setTitle:@"Sign Up" forState:UIControlStateNormal];
        self.onboardingDescription.text = @"Post Photos, Videos, Audio, and Live Video to Stations";
        self.index = 4;
        break;
    }
}

}


- (IBAction)backButton:(id)sender {
   //NEED TO MOVE PAGEVIEWCONTROLLER BACK.... self.index--?


}
- (IBAction)nextButton:(id)sender {
    //NEED TO MOVE PAGEVIEWCONTROLLER FORWARD.... self.index++?
}