Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS

How to call view controller by story board ID?

I am working on a project in Xcode (iOS, Objective C) that will use a page view controller for navigation. I will have 5 view controllers, each with its own storyboard ID. The storyboard IDs will be stored in an array. The Page View Controller will call the VC on start up (index 0) from the array. From there the user will swipe right to navigate through the screens, and then back left if user chooses to do so.

I am receiving errors in the code in my .m file. Here is the code:

import "RootViewController.h"

@interface RootViewController ()

@end

@implementation RootViewController

  • (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. _vcIds = @[@"Home Page", @"Personal Information"];

    // create page view controller self.PageViewController =[self.storyboard instantiateViewControllerWithIdentifier: @"PageViewController"]; self.PageViewController.dataSource = self; _PageViewController *_PageViewController = [self viewControllerAtIndex: 0]; NSArray *viewControllers = @[_PageViewController]; [self.PageViewController setViewControllers:viewControllers direction: UIPageViewControllerNavigationDirectionForward animated: NO completion: nil];

The _PageViewController *_PageViewController line gives the error: Invalid operands to binary expression ('UIPageViewController * and UIPageViewController *'). What does this mean and how to fix it? This is a red flag error.

The line above that: self.PageViewController.dataSource = self; gives a yellow flag warning: 'Assigning to 'id<UIPageViewControllerDataSource>_Nullabe' from incompatitle type 'RootViewController *const_strong'. What does that mean and how do I fix it?