我的代码有一点小问题。当我尝试在我的应用程序中有两个页面视图控制器时,我不断收到以下消息。两者都被用于不同的事情。我复制并粘贴了我实现的第一个页面控制器的代码,然后更改了名称以防止冲突。我最近开始收到此错误消息,现在我的程序无法运行。谁能告诉我为什么会这样?
我还收到一个错误,指出协议中的方法“pageViewController:viewControllerBeforeViewController:”未实现。我不太确定这是否是一个相关问题,但有人知道我为什么会得到这个吗?
#import "StorageViewController.h"
#import "InstructionContentViewController.h"
@interface StorageViewController ()
@end
@implementation StorageViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Create the data model
_pageInstructTitles = @[@"Over 200 Tips and Tricks", @"Discover Hidden Features", @"Bookmark Favorite Tip", @"Free Regular Update"];
_pageInstructImages = @[@"instructions1.png", @"instructions2.png", @"instructions3.png", @"instructions4.png"];
// Create page view controller
self.instructViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"InstructionViewController"];
self.instructViewController.dataSource = self;
InstructionContentViewController *startingInstructViewController = [self viewControllerAtIndex:0];
NSArray *viewInstructControllers = @[startingInstructViewController];
[self.instructViewController setViewControllers:viewInstructControllers direction:UIPageViewControllerNavigationDirectionForward animated:NO completion:nil];
// Change the size of page view controller
self.instructViewController.view.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height - 30);
[self addChildViewController:_instructViewController];
[self.view addSubview:_instructViewController.view];
[self.instructViewController didMoveToParentViewController:self];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)startInstructWalkthrough:(id)sender {
InstructionContentViewController *startingInstructViewController = [self viewControllerAtIndex:0];
NSArray *viewControllers = @[startingInstructViewController];
[self.instructViewController setViewControllers:viewControllers direction:UIPageViewControllerNavigationDirectionReverse animated:NO completion:nil];
}
#pragma mark - Page View Controller Data Source Methods:
- (UIViewController *)instructViewController:(UIPageViewController *)instructViewController viewControllerBeforeViewController:(UIViewController *)viewInstructController
{
NSUInteger index = ((InstructionContentViewController*) viewInstructController).instructPageIndex;
if ((index == 0) || (index == NSNotFound)) {
return nil;
}
index--;
return [self viewControllerAtIndex:index];
}
- (UIViewController *)instructViewController:(UIPageViewController *)instructViewController viewControllerAfterViewController:(UIViewController *)viewInstructController
{
NSUInteger index = ((InstructionContentViewController*) viewInstructController).instructPageIndex;
if (index == NSNotFound) {
return nil;
}
index++;
if (index == [self.pageInstructTitles count]) {
return nil;
}
return [self viewControllerAtIndex:index];
}
- (InstructionContentViewController *)viewControllerAtIndex:(NSUInteger)index
{
if (([self.pageInstructTitles count] == 0) || (index >= [self.pageInstructTitles count])) {
return nil;
}
// Create a new view controller and pass suitable data.
InstructionContentViewController *instructionContentViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"InstructionContentViewController"];
instructionContentViewController.instructImageFile = self.pageInstructImages[index];
instructionContentViewController.instructTitleText = self.pageInstructTitles[index];
instructionContentViewController.instructPageIndex = index;
return instructionContentViewController;
}
- (NSInteger)presentationCountForPageViewController:(UIPageViewController *)instructViewController
{
return [self.pageInstructTitles count];
}
- (NSInteger)presentationIndexForPageViewController:(UIPageViewController *)instructViewController
{
return 0;
}
@end