UIPageviewController използва срив на Storyboard

Ще направя страница с уроци с помощта на UIPageViewController.

Но се случи катастрофа. Не можах да намеря точката на срива.

Опитвам се да използвам UIPageViwController директно, а не да използвам в UIViewController.

dataSource работи. но при опит за извикване на [self setViewControllers:@[pageZero] direction:UIPageViewControllerNavigationDirectionForward animated:YES completion:nil]; възникна грешка като по-долу.

UserGuidePageViewController е свързан с UIPagveViewController Frame в десния борд.

Следва заглавката

#import <UIKit/UIKit.h>

@interface UserGuidePageViewController : UIPageViewController <UIPageViewControllerDataSource> {

}


@end

Следва код

#import "UserGuidePageViewController.h"
#import "UserGuideViewController.h"


@interface UserGuidePageViewController () {

}

@property (nonatomic, retain) NSArray *array;

@end

@implementation UserGuidePageViewController


- (id)initWithCoder:(NSCoder *)aDecoder
{
    self = [super initWithCoder:aDecoder];

    if (self) {
        self.dataSource = self;
    }

    return self;
}

- (UserGuideViewController *)userGuideViewForPageIndex:(NSUInteger)pageIndex
{
    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
    UserGuideViewController *targetViewController = [storyboard instantiateViewControllerWithIdentifier:@"UserGuideViewController"];

    return targetViewController;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    UserGuideViewController *pageZero = [self userGuideViewForPageIndex:0];

    [self setViewControllers:@[pageZero] direction:UIPageViewControllerNavigationDirectionForward animated:YES completion:nil];
    --> Crash happened here!!!
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Page View Controller Data Source

- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerBeforeViewController:(UIViewController *)viewController
{
    NSUInteger index = [(UserGuideViewController *)viewController pageIndex];

    return [self userGuideViewForPageIndex:(index - 1)];
}

- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerAfterViewController:(UIViewController *)viewController
{
    NSUInteger index = [(UserGuideViewController *)viewController pageIndex];

    return [self userGuideViewForPageIndex:(index + 1)];
}

- (NSInteger)presentationCountForPageViewController:(UIPageViewController *)pageViewController
{
    // The number of items reflected in the page indicator.
    return 1;
}

- (NSInteger)presentationIndexForPageViewController:(UIPageViewController *)pageViewController
{
    // The selected item reflected in the page indicator.
    return 0;
}

Следва грешка.

*** Assertion failure in -[_UIQueuingScrollView setView:direction:animated:completion:], /SourceCache/UIKit/UIKit-2903.23/_UIQueuingScrollView.m:671
2013-12-18 15:23:35.779 Natural Calendar[4497:60b] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid parameter not satisfying: view'
*** First throw call stack:
(0x30ef6f4b 0x3b6d36af 0x30ef6e25 0x3189efe3 0x33ba3321 0x33b382eb 0x33b38407 0xf4715 0x3366e37b 0x3366e139 0xf0c45 0x1062d9 0x1106c3 0x3369e713 0x3369e6b3 0x3369e691 0x3368a11f 0x3369e107 0x3369ddd9 0x33698e65 0x3366e79d 0x3366cfa3 0x30ec2183 0x30ec1653 0x30ebfe47 0x30e2ac27 0x30e2aa0b 0x35b0b283 0x336ce049 0xecd09 0x3bbdbab7)
libc++abi.dylib: terminating with uncaught exception of type NSException

Всъщност промених в стила на шаблона Xcode.

Но тази грешка също се появява.

- (void)viewDidLoad
{
    [super viewDidLoad];

    _pageViewController = [[UIPageViewController alloc] initWithTransitionStyle:UIPageViewControllerTransitionStyleScroll navigationOrientation:UIPageViewControllerNavigationOrientationHorizontal options:nil];
    [_pageViewController setDataSource:self];

    UserGuideViewController *pageZero = [self userGuideViewForPageIndex:0];

    [_pageViewController setViewControllers:@[pageZero] direction:UIPageViewControllerNavigationDirectionForward animated:YES completion:nil];

    [self addChildViewController:_pageViewController];
    [self.view addSubview:[_pageViewController view]];

    CGRect pageViewRect = self.view.bounds;
    //pageViewRect = CGRectInset(pageViewRect, 40.0, 40.0);
    _pageViewController.view.frame = pageViewRect;

    [_pageViewController didMoveToParentViewController:self];
}

Не знам какъв е проблемът. При избора на UIPageViewControllerTransitionStyleScroll възникна грешка. Когато изберете UIPageViewControllerTransitionStylePageCurl, грешката не се е случила.


person mkjwa    schedule 18.12.2013    source източник
comment
трябва също да промените пакета си от нула на [NSBundle mainBundle] мисля, че РЕДАКТИРАНЕ: съжалявам, просто прочетете документацията, ако посочите нула, той автоматично търси в mainBundle за сценария   -  person dehlen    schedule 19.12.2013


Отговори (2)


@interface UserGuidePageViewController : UIPageViewController <UIPageViewControllerDataSource> {

променете този ред с

@interface UserGuidePageViewController : UIViewController <UIPageViewControllerDataSource> {

Означава, че можете да използвате UIViewcontroller за това

вижте тази връзка за справка.

и тази друга връзка, която се използва сценарий.

person Maulik Kundaliya    schedule 18.12.2013
comment
Има ли само начин да се използва UIViewController? Проверих кода на шаблона в Нов проект. Опитвам се да използвам UIPageViewController, защото изглежда използва UIPageViewController без деклариране на свойството за UIPageViewController. - person mkjwa; 18.12.2013
comment
Тази връзка изглежда работи, като разширява директно UIPageViewController, но има друг проблем. - person mkjwa; 18.12.2013
comment
съжалявам, скъпа, не използвах това като разширяване на uipageviewcontroller. - person Maulik Kundaliya; 18.12.2013

Намерих loadView() { } деклариран на страница ContentViewController. Въпреки това loadView() остава празен без извикване на [super loadView];. В резултат на това изгледът ще остане nil.

Сега изглежда, че работи след премахването на метода, loadView().

person mkjwa    schedule 19.12.2013