UIPageViewController委托,dataSource和&界面错误

时间:2017-05-08 01:58:10

标签: ios objective-c uipageviewcontroller

我正在开发一个使用UIPageViewController的应用程序,以便我可以从左向右滑动以浏览页面(ViewControllers)。从我原来的帖子开始,我已经编写了代码。但我收到三个错误。

错误1:在'IntroPages'类型的对象上找不到属性'委托' 错误2:在'IntroPages'类型的对象上找不到属性'dataSource' 错误3:'IntroPages'没有可见的@interface声明选择器'setViewControllers:direction:animated:completion:'

所有三个错误都在viewDidLoad的第一部分(部分位于{}括号中)。前两个用于viewDidLoad下的代码,下面是第三个5行。

.h文件中引用了delegate和dataSource。他们为什么没被找到? Wy是否在'IntroPages'中没有可见的@interface?

代码如下。

IntroPages.h

#import <UIKit/UIKit.h>

@interface IntroPages : UIViewController
<UIPageViewControllerDelegate, UIPageViewControllerDataSource>

@end

IntroPages.m

#import "IntroPages.h"

@interface IntroPages ()

@end

@implementation IntroPages
{
    NSArray *myViewControllers;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.delegate = self; 
    self.dataSource = self;

    UIViewController *p1 = [self.storyboard
                            instantiateViewControllerWithIdentifier:@"Intro1ID"];
    UIViewController *p2 = [self.storyboard
                            instantiateViewControllerWithIdentifier:@"Intro2ID"];
    UIViewController *p3 = [self.storyboard
                            instantiateViewControllerWithIdentifier:@"Intro3ID"];
    UIViewController *p4 = [self.storyboard
                            instantiateViewControllerWithIdentifier:@"Intro4ID"];

    myViewControllers = @[p1,p2,p3,p4];

    [self setViewControllers:@[p1]
                   direction:UIPageViewControllerNavigationDirectionForward
                    animated:NO completion:nil];

    NSLog(@"loaded!");
}


@end

0 个答案:

没有答案