ios - UIPageviewController 使用 Storyboard 崩溃

标签 ios objective-c storyboard uipageviewcontroller

我将使用 UIPageViewController 制作一个教程页面。

但是崩溃发生了。我找不到发生崩溃的点。

我试图直接使用 UIPageViwController,而不是在 UIViewController 中使用。

数据源有效。但是当尝试调用 [self setViewControllers:@[pageZero] 方向:UIPageViewControllerNavigationDirectionForward 动画:YES 完成: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时,没有发生错误。

最佳答案

@interface UserGuidePageViewController : UIPageViewController <UIPageViewControllerDataSource> {

更改此行

@interface UserGuidePageViewController : UIViewController <UIPageViewControllerDataSource> {

意味着您可以为此使用 UIViewcontroller

参见this链接供引用。

还有这个link这是使用的 Storyboard。

关于ios - UIPageviewController 使用 Storyboard 崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20651287/

相关文章:

ios - 无法使具有标识符 Cell 的单元格出列 - 必须为标识符注册一个 nib 或一个类,或者在 Storyboard中连接一个原型(prototype)单元格?

ios - 在 Storyboard中创建 UIView 连接时获取 "Couldn' t 编译连接

ios - 在 Storyboard 中实现视频 View

ios - 围绕 anchor 将图像旋转 90 度

iphone - TWTeetComposeViewController发布新推文后执行自定义代码

ios - 使用混合的 Swift 和 Objective-C 代码创建框架

ios - 带有 Pan 手势冲突的 ScrollView 和侧边菜单

ios - 向 UIBezierPath 动态添加值

iphone - 保存登录凭据 Xcode

Objective-C:逐行读取文件