Xcode 页面视图控制器-从图像到另一个视图控制器

Xcode 页面视图控制器-从图像到另一个视图控制器,xcode,storyboard,uipageviewcontroller,Xcode,Storyboard,Uipageviewcontroller,我对我要完成的事情有点困惑。我有一个页面视图控制器,它有一个包含图像数组列表的数据源。这实际上是一个用户可以翻阅的教程。我想做的是将最后一页设为登录屏幕,这样用户就可以输入信息并点击登录按钮。我原以为这就像在阵列中添加登录视图控制器一样简单,但哦,我错了。D:当我尝试时,我遇到了以下错误: *由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“-[UIViewController\u isResizable]:未识别的选择器已发送到实例0xa16066

我对我要完成的事情有点困惑。我有一个页面视图控制器,它有一个包含图像数组列表的数据源。这实际上是一个用户可以翻阅的教程。我想做的是将最后一页设为登录屏幕,这样用户就可以输入信息并点击登录按钮。我原以为这就像在阵列中添加登录视图控制器一样简单,但哦,我错了。D:当我尝试时,我遇到了以下错误:

*由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“-[UIViewController\u isResizable]:未识别的选择器已发送到实例0xa160660”

我真的很抱歉,我对这一切都不熟悉,只是想让我的头脑清醒一下。以下是我的代码(通过实际使用此网站完成):

我的数据源(ModelController.h)

父级(RootViewController.h)

子对象(DataViewController.h)

同样,这里讨论的代码是我试图将视图控制器作为最后一页添加到数据源的代码:

_pageData = [[NSArray alloc] initWithObjects:

                [UIImage imageNamed:@"tutorial1.png"],
                [UIImage imageNamed:@"tutorial2.png"],
                [UIImage imageNamed:@"lastWishes.png"],
                [UIImage imageNamed:@"todo.png"],
                [UIImage imageNamed:@"web.png"],
             (LoginViewController*)[[UIViewController alloc] init],

                 nil];
以及在运行时出现无法识别的选择器错误。我也试过这个:

- (id)init
{
self = [super init];
if (self)
{
    LoginViewController *viewController = [self.storyboard instantiateViewControllerWithIdentifier:@"LoginViewController"];
    // Create the data model
    _pageData = [[NSArray alloc] initWithObjects:

                    [UIImage imageNamed:@"tutorial1.png"],
                    [UIImage imageNamed:@"tutorial2.png"],
                    [UIImage imageNamed:@"lastWishes.png"],
                    [UIImage imageNamed:@"todo.png"],
                    [UIImage imageNamed:@"web.png"],
                     viewController,

                     nil];
}
return self;
}

任何建议都很好。谢谢

您的想法是100%正确的,但您的实施是不正确的

这一行:

dataViewController.dataObject=self.pageData[index]


非常可疑,因为在登录屏幕的情况下,这将返回UIViewController。我建议您使用页面数据,如果它已经是UIViewController子类,只需返回它,如果它(在您的情况下)是UIImage,请将其添加为数据对象。

Hey Paul。非常感谢你回复我的帖子。关于你的建议,你能用一些示例代码来更新吗?我只是想知道类型检查是应该在您所引用的方法中进行,还是应该在我创建页面数据之前进行。请原谅我的无知,哈哈
#import <UIKit/UIKit.h>

@interface RootViewController : UIViewController <UIPageViewControllerDelegate>

@property (strong, nonatomic) UIPageViewController *pageViewController;

@end
#import "RootViewController.h"

#import "ModelController.h"

#import "DataViewController.h"

@interface RootViewController ()
@property (readonly, strong, nonatomic) ModelController *modelController;
@end

@implementation RootViewController

@synthesize modelController = _modelController;

- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
// Configure the page view controller and add it as a child view controller.
self.pageViewController = [[UIPageViewController alloc]   initWithTransitionStyle:UIPageViewControllerTransitionStylePageCurl  navigationOrientation:UIPageViewControllerNavigationOrientationVertical options:nil];
self.pageViewController.delegate = self;

DataViewController *startingViewController = [self.modelController viewControllerAtIndex:0 storyboard:self.storyboard];
NSArray *viewControllers = @[startingViewController];
[self.pageViewController setViewControllers:viewControllers direction:UIPageViewControllerNavigationDirectionForward animated:NO completion:NULL];

self.pageViewController.dataSource = self.modelController;

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

// Set the page view controller's bounds using an inset rect so that self's view is visible around the edges of the pages.
CGRect pageViewRect = self.view.bounds;
self.pageViewController.view.frame = pageViewRect;

[self.pageViewController didMoveToParentViewController:self];

// Add the page view controller's gesture recognizers to the book view controller's view so that the gestures are started more easily.
self.view.gestureRecognizers = self.pageViewController.gestureRecognizers;
}

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

- (ModelController *)modelController
{
// Return the model controller object, creating it if necessary.
// In more complex implementations, the model controller may be passed to the view controller.
if (!_modelController) {
    _modelController = [[ModelController alloc] init];
}
return _modelController;
}

#pragma mark - UIPageViewController delegate methods

/*
- (void)pageViewController:(UIPageViewController *)pageViewController didFinishAnimating:    (BOOL)finished previousViewControllers:(NSArray *)previousViewControllers transitionCompleted:  (BOOL)completed
{

}
*/

- (UIPageViewControllerSpineLocation)pageViewController:(UIPageViewController *)pageViewController spineLocationForInterfaceOrientation:(UIInterfaceOrientation)orientation
{
// Set the spine position to "min" and the page view controller's view controllers array to contain just one view controller. Setting the spine position to 'UIPageViewControllerSpineLocationMid' in landscape orientation sets the doubleSided property to YES, so set it to NO here.
UIViewController *currentViewController = self.pageViewController.viewControllers[0];
NSArray *viewControllers = @[currentViewController];
[self.pageViewController setViewControllers:viewControllers direction:UIPageViewControllerNavigationDirectionForward animated:YES completion:NULL];

self.pageViewController.doubleSided = NO;
return UIPageViewControllerSpineLocationMin;
}


@end
#import <UIKit/UIKit.h>

@interface DataViewController : UIViewController
@property (strong, nonatomic) id dataObject;
@property (weak, nonatomic) IBOutlet UIImageView *imageView;

@end
#import "DataViewController.h"

@interface DataViewController ()

@end

@implementation DataViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
    // Custom initialization
}
return self;
}

- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
}

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

- (void) viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
self.imageView.image = _dataObject;
}

@end
_pageData = [[NSArray alloc] initWithObjects:

                [UIImage imageNamed:@"tutorial1.png"],
                [UIImage imageNamed:@"tutorial2.png"],
                [UIImage imageNamed:@"lastWishes.png"],
                [UIImage imageNamed:@"todo.png"],
                [UIImage imageNamed:@"web.png"],
             (LoginViewController*)[[UIViewController alloc] init],

                 nil];
- (id)init
{
self = [super init];
if (self)
{
    LoginViewController *viewController = [self.storyboard instantiateViewControllerWithIdentifier:@"LoginViewController"];
    // Create the data model
    _pageData = [[NSArray alloc] initWithObjects:

                    [UIImage imageNamed:@"tutorial1.png"],
                    [UIImage imageNamed:@"tutorial2.png"],
                    [UIImage imageNamed:@"lastWishes.png"],
                    [UIImage imageNamed:@"todo.png"],
                    [UIImage imageNamed:@"web.png"],
                     viewController,

                     nil];
}
return self;
}