Note that there are some explanatory texts on larger screens.

plurals
  1. POPage View Controller - from images to another view controller
    primarykey
    data
    text
    <p>I'm a bit perplexed about what I'm trying to accomplish. I have a page view controller that has a data source containing an array list of images. It's actually a tutorial that a user can flip through. What I'm trying to do is make the last page a log in screen so the user can enter info and hit a login button. I thought this would be as simple as adding a login view controller to the array but oooh how wrong I was D: When I tried that I got this error:</p> <p><em>*</em> Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIViewController _isResizable]: unrecognized selector sent to instance 0xa160660'</p> <p>I do apologise for being such a noob I'm new to all of this just trying to get my head around it. Here's my code (accomplished by using this site actually):</p> <p>My data source (ModelController.h)</p> <pre><code>#import &lt;Foundation/Foundation.h&gt; @class DataViewController; @interface ModelController : NSObject &lt;UIPageViewControllerDataSource&gt; - (DataViewController *)viewControllerAtIndex:(NSUInteger)index storyboard:(UIStoryboard *)storyboard; - (NSUInteger)indexOfViewController:(DataViewController *)viewController;` @end </code></pre> <p>ModelController.m</p> <pre><code>#import "ModelController.h" #import "DataViewController.h" #import "LoginViewController.h" @interface ModelController() @property (readonly, strong, nonatomic) NSArray *pageData; @end @implementation ModelController - (id)init { self = [super init]; if (self) { // 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"], (LoginViewController*)[[UIViewController alloc] init], nil]; } return self; } - (DataViewController *)viewControllerAtIndex:(NSUInteger)index storyboard:(UIStoryboard *)storyboard { // Return the data view controller for the given index. if (([self.pageData count] == 0) || (index &gt;= [self.pageData count])) { return nil; } // Create a new view controller and pass suitable data. DataViewController *dataViewController = [storyboard instantiateViewControllerWithIdentifier:@"DataViewController"]; dataViewController.dataObject = self.pageData[index]; return dataViewController; } - (NSUInteger)indexOfViewController:(DataViewController *)viewController { // Return the index of the given data view controller. // For simplicity, this implementation uses a static array of model objects and the view controller stores the model object; you can therefore use the model object to identify the index. return [self.pageData indexOfObject:viewController.dataObject]; } #pragma mark - Page View Controller Data Source - (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerBeforeViewController:(UIViewController *)viewController { NSUInteger index = [self indexOfViewController:(DataViewController *)viewController]; if ((index == 0) || (index == NSNotFound)) { return nil; } index--; return [self viewControllerAtIndex:index storyboard:viewController.storyboard]; } - (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerAfterViewController:(UIViewController *)viewController { NSUInteger index = [self indexOfViewController:(DataViewController *)viewController]; if (index == NSNotFound) { return nil; } index++; if (index == [self.pageData count]) { return nil; } return [self viewControllerAtIndex:index storyboard:viewController.storyboard]; } @end </code></pre> <p>The Parent (RootViewController.h)</p> <pre><code>#import &lt;UIKit/UIKit.h&gt; @interface RootViewController : UIViewController &lt;UIPageViewControllerDelegate&gt; @property (strong, nonatomic) UIPageViewController *pageViewController; @end </code></pre> <p>RootViewController.m</p> <pre><code>#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 </code></pre> <p>The Child (DataViewController.h)</p> <pre><code>#import &lt;UIKit/UIKit.h&gt; @interface DataViewController : UIViewController @property (strong, nonatomic) id dataObject; @property (weak, nonatomic) IBOutlet UIImageView *imageView; @end </code></pre> <p>DataViewController.m</p> <pre><code>#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 </code></pre> <p>Once again, the code in question is here where I'm trying to add a view controller to the data source as the last page:</p> <pre><code>_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]; </code></pre> <p>and getting unrecognized selector error when at runtime. I've also tried this as well:</p> <pre><code>- (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; } </code></pre> <p>Any suggestions would be great. THanks!!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload