2014-04-11 2 views
-1

메소드에 - (void)setViewControllers:(NSArray *)viewControllers direction:(UIPageViewControllerNavigationDirection)direction animated:(BOOL)animated completion:(void (^)(BOOL finished))completion이 설정되어 있습니다. 메서드가 호출 될 때마다 다음 페이지로 이동하지 않습니다. 대신 UIPageViewController 스토리 보드로 이동 한 다음 충돌합니다. 내가 뭘 잘못하고 있는지 모르겠다. 나는 pageviewcontroller에 대해 MSPageViewController을 사용하고 있습니까?UIPageViewController setViewController로 인해 앱이 다운 됨

Heres는 내 코드 :

UIViewController *viewcont = [[UIViewController alloc]init]; 

NSArray *viewControllers = [NSArray arrayWithObject:viewcont]; 

[self setViewControllers:viewControllers direction:UIPageViewControllerNavigationDirectionForward animated:YES completion:nil]; 

감사합니다.

pageIndex 속성이 합성 된 MSPageViewControllerChild를 모두 준수하는 스토리 보드가 3 개 있습니다. IntroPageViewController는 첫 번째 스토리 보드 (p1)입니다.

PagingViewController.h : 당신이 MSPageViewControllerChild을 준수하지 않는 컨트롤러, MSPageViewController을 사용하고 같은

// 
// 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

오류 로그를 추가 할 수 있습니까? – shannoga

+0

@shannoga가 방금 질문에 추가했습니다. – user3186310

+1

예외 중단 점을 추가하고 충돌이 발생한 위치를 확인하십시오. –

답변

1

보인다. 문서에서

:

그들 [컨트롤러]의 각각은 (당신이 어떤 추가 기능을 추가 할 필요가 없습니다 경우 MSPageViewControllerPage을 사용할 수 있습니다) MSPageViewControllerChild을 준수하는 클래스 여야합니다.

+0

내 모든 페이지는'MSPageViewControllerChild'를 따르거나'MSPageViewCotrollerPage'를 사용 중입니다. 내 스토리 보드는'MSPageViewControllerChild'와'MSPageViewCotrollerPage'를 혼합하여 만들 수 있습니다. 정말 고마워 답변, 감사합니다 – user3186310

+0

당신은'pageIndex' 속성을 종합하고 있습니까? – NachoSoto

+0

예, 방금 UIViewController에서 UIViewController를 변경했습니다. * viewcont = [[UIViewController alloc] init]; MSPageViewControllerChild를 준수하는 클래스에 추가합니다. 응용 프로그램이 충돌하지 않지만 다음 페이지로 이동하지 않습니다. 그냥 빈 페이지로 간다. (내가 UIPageViewController 스토리 보드를 이해함). 감사. – user3186310