PageViewController中无法识别的选择器问题

时间:2017-06-10 00:00:44

标签: ios objective-c uipageviewcontroller

enter image description here

我正在制作简单的介绍画面。屏幕在滑动时滑动,但我也想用按钮轻击滑动介绍屏幕但是当我点击下一个按钮时它显示错误。

完整代码

 #import <UIKit/UIKit.h>

  #import "WalkthroughPageViewController.h"

@interface WalkthroughContentViewController : UIViewController


@property (weak, nonatomic) IBOutlet UILabel *pageLbl;

@property (weak, nonatomic) IBOutlet UIButton *nextBtn;

@property(strong,nonatomic)WalkthroughPageViewController *pageVC;
@property NSUInteger index;
@property NSString *heading;


@end

WalkthroughContentViewController.m

 #import "WalkthroughContentViewController.h"


@interface WalkthroughContentViewController ()

@end

@implementation WalkthroughContentViewController



- (void)viewDidLoad {
    [super viewDidLoad];

    self.pageLbl.text = self.heading;


    switch (self.index) {
        case 0:
       case 1:
            [self.nextBtn setTitle:@"Next" forState:UIControlStateNormal];
            break;
        case 2:
            [self.nextBtn setTitle:@"Done" forState:UIControlStateNormal];
        break;

    default:
        break;
}


}

- (IBAction)nextBtn:(id)sender {


    switch (self.index) {
        case 0:
            case 1:
            self.pageVC  = ((WalkthroughPageViewController*)self.parentViewController);


            [self.pageVC forward:self.index];
            break;
        case 2:

            [self performSegueWithIdentifier:@"LoginScreen" sender:nil];

            break;

        default:
            break;
     }



}



@end

WalkthroughPageViewController.h

#import <UIKit/UIKit.h>

@interface WalkthroughPageViewController :UIPageViewController<UIPageViewControllerDataSource>

@property (strong, nonatomic) UIPageViewController *pageViewController;

@property NSArray *pageHeading;

-(void)forward:(NSUInteger)index;

@end

WalkthroughPageViewController.m

    #import "WalkthroughPageViewController.h"
 #import "WalkthroughContentViewController.h"

@interface WalkthroughPageViewController ()

@end

@implementation WalkthroughPageViewController


NSUInteger indexP;

- (void)viewDidLoad {
      [super viewDidLoad];

  self.pageHeading = @[@"page1",@"page2",@"page3"];

    self.pageViewController = [[UIPageViewController alloc] init];

    self.pageViewController.dataSource = self;

    WalkthroughContentViewController *startingViewController = [self viewControllerAtIndex:0];
    NSArray *viewControllers = @[startingViewController];
    [_pageViewController setViewControllers:viewControllers direction:UIPageViewControllerNavigationDirectionForward animated:NO completion:nil];



   [self addChildViewController:self.pageViewController];
  [self.view addSubview:self.pageViewController.view];
 [self.pageViewController didMoveToParentViewController:self];




}



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

indexP  = ((WalkthroughContentViewController*) viewController).index;

if ((indexP == 0) || (indexP == NSNotFound)) {
    return nil;
}

indexP--;


    return [self viewControllerAtIndex:indexP];

}

- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerAfterViewController:(UIViewController *)viewController
 {
indexP = ((WalkthroughContentViewController*) viewController).index;

if (indexP == NSNotFound) {
    return nil;
}

indexP++;
if (indexP == [self.pageHeading count]) {
    return nil;
}

    return [self viewControllerAtIndex:indexP];



}


- (WalkthroughContentViewController *)viewControllerAtIndex:(NSUInteger)index
{
if ((index == NSNotFound) || (index >= [self.pageHeading count])) {
    return nil;
}

// Create a new view controller and pass suitable data.
WalkthroughContentViewController *pageContentViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"WalkthroughContentViewController"];
pageContentViewController.heading = self.pageHeading[index];

pageContentViewController.index = index;

return pageContentViewController;
}

- (NSInteger)presentationCountForPageViewController:(UIPageViewController *)pageViewController
{
return [self.pageHeading count];
}

- (NSInteger)presentationIndexForPageViewController:(UIPageViewController *)pageViewController
{
return 0;
}


-(void)forward:(NSUInteger)index{


    [self.pageViewController  setViewControllers:@[[self viewControllerAtIndex:index]] direction:UIPageViewControllerNavigationDirectionForward animated:YES completion:nil];
}


@end

**错误:: **

    [UIPageViewController forward:]: unrecognized selector sent to instance

0 个答案:

没有答案