UIPageViewController setViewController вызывает сбой приложения
У меня есть - (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
1 ответ
Похоже, вы используете MSPageViewController
с контроллером, который не соответствует MSPageViewControllerChild
,
Из документации:
Каждый из них [контроллеры] должен быть классом, который соответствует MSPageViewControllerChild (если вам не нужно добавлять какие-либо дополнительные функции, вы можете использовать MSPageViewControllerPage).