我在方法中设置了- (void)setViewControllers:(NSArray *)viewControllers direction:(UIPageViewControllerNavigationDirection)direction animated:(BOOL)animated completion:(void (^)(BOOL finished))completion
。每当调用该方法时,它都不会转到下一页。相反,它转到UIPageViewController故事板然后崩溃。我不确定我做错了什么。我正在使用MSPageViewController作为pageviewcontroller,可能就是这样吗?
继承我的代码:
UIViewController *viewcont = [[UIViewController alloc]init];
NSArray *viewControllers = [NSArray arrayWithObject:viewcont];
[self setViewControllers:viewControllers direction:UIPageViewControllerNavigationDirectionForward animated:YES completion:nil];
感谢。
有3个故事板都符合MSPageViewControllerChild并合成了pageIndex属性。 IntroPageViewController是第一个故事板(p1)。
PagingViewController.h:
//
// PagingViewController.m
// MordechaiLevi
//
// Created by Mordechai Levi on 4/10/14.
// Copyright (c) 2014 Mordechai Levi. All rights reserved.
//
#import "PagingViewController.h"
#import "IntroPageViewController.h"
#import "MSPageViewController.h"
@interface PagingViewController ()
@end
@implementation PagingViewController
- (void)viewDidLoad
{
[super viewDidLoad];
self.device = [UIDevice currentDevice];
self.device.proximityMonitoringEnabled = YES;
if (self.device.proximityMonitoringEnabled == YES) {
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(sensorCovered) name:@"UIDeviceProximityStateDidChangeNotification" object:nil];
}else{
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Uh Oh!" message:@"To use this app you need a device with a proximity sensor." delegate:self cancelButtonTitle:@"Got it" otherButtonTitles:nil, nil];
[alert show];
}
self.view.backgroundColor = [UIColor colorWithRed:0.2 green:0.859 blue:0.643 alpha:1.0];
}
- (UIStatusBarStyle)preferredStatusBarStyle {
return UIStatusBarStyleLightContent;
}
- (void)sensorCovered {
if (self.device.proximityState == YES) {
IntroPageViewController *viewcont = [[IntroPageViewController alloc]init];
NSArray *viewControllers = [NSArray arrayWithObject:viewcont];
[self setViewControllers:viewControllers direction:UIPageViewControllerNavigationDirectionForward animated:YES completion:nil];
NSLog(@"sensor covered");
}else{
NSLog(@"sensor not covered");
}
}
- (NSArray *)pageIdentifiers {
return @[@"p1", @"p2", @"p3"];
}
@end
答案 0 :(得分:1)
您似乎正在使用MSPageViewController
,控制器不符合MSPageViewControllerChild
。
来自文档:
每个[控制器]必须是符合MSPageViewControllerChild的类(如果你不需要为它添加任何额外的功能,你可以使用MSPageViewControllerPage。)