+ Start a Discussion
firechimpfirechimp 

Mobile iOS SDK - Using Storyboards with Salesforce oAuth template

Hi all,

The updated SDK rules, but I am having a little issue getting the iOS view controller to initalise my storyboard after the login process has completed (in my AppDelegate), I am trying to just point to my storyboard instead of the rootview provided in the template.

 

Please see my AppDelegate code bellow:

- (void)initializeAppViewState
{
    self.window.rootViewController = [[InitialViewController alloc] initWithNibName:nil bundle:nil];
    [self.window makeKeyAndVisible];
}

- (void)setupRootViewController
{
    NSBundle *bundle = [NSBundle mainBundle];
    UIStoryboard *sb = [UIStoryboard storyboardWithName:@"StoryboardiPhone" bundle:bundle];
    RootViewController *rootView = (RootViewController*)[sb instantiateViewControllerWithIdentifier:@"mainPage"];
    self.window.rootViewController = rootView;
}

 Everything else in the AppDelegate remains the same, the two classes referenced here are:

#import "InitialViewController.h"

@implementation InitialViewController

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

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

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

@end

 

#import "RootViewController.h"

@implementation RootViewController

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

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

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

@end

 This should direct them into the storyboard with the rootViewController, which should provide a 'UITabBarController' from here they will be able to click a tab to display the original 'UITableViewController' which will return some records from salesforce for display.

 

The ERROR that I recieve is:

2013-09-28 11:15:01.738 Example 1[340:a0b] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '-[UITableViewController loadView] loaded the "yRf-rA-8Y5-view-2PQ-Tj-Ddg" nib but didn't get a UITableView.'

 It appear that the rootViewController is expecting a UITableViewController, but I don't understand why this would be or how to get around it.

Has anyone successfuly redirected to a storyboard from the completion of the login using the template provided? If so how did you get around this issue?

 

Best Answer chosen by Admin (Salesforce Developers) 
Kevin HawkinsKevin Hawkins

Yes, I can basically use your logic for instantiating the storyboard in AppDelegate, implementing a completely different UIViewController class, and I don't seem to have any problems.  The authentication piece doesn't have any knowledge of any of the views or view controllers associated with its actions.  It simply authenticates, then hands off to the completion block.  So the code that you've implemented in setupRootViewController is wholly responsible for initiating your storyboard flow.

 

It seems like maybe there are some artifacts from the previous implementation of RootViewController that may be hanging around in your development enviornment.  I would recommend creating a new UIViewController class with a different name (BaseViewController or something to that effect), and see if you have the same issues.  I don't see anything in the code you've posted that should cause the kind of error you're seeing.

All Answers

Kevin HawkinsKevin Hawkins
Did you change the original RootViewController.h? The sample view controller class inherits from UITableViewController.
firechimpfirechimp

Hi Kevin,

Thanks for your reply, yes I did update this.

 

#import <UIKit/UIKit.h>
#import "SFRestAPI.h"

@interface RootViewController : UITabBarController

@end

 

I think that there may be something in the sdk login stuff that expects the view controller to be a UITableViewController, but this seams a little odd to me. I have been looking throught the salesforce core files etc... and have found nothing that would do this.

 

Have you managed to get the template to work with a storyboard?

 

Kevin HawkinsKevin Hawkins

Yes, I can basically use your logic for instantiating the storyboard in AppDelegate, implementing a completely different UIViewController class, and I don't seem to have any problems.  The authentication piece doesn't have any knowledge of any of the views or view controllers associated with its actions.  It simply authenticates, then hands off to the completion block.  So the code that you've implemented in setupRootViewController is wholly responsible for initiating your storyboard flow.

 

It seems like maybe there are some artifacts from the previous implementation of RootViewController that may be hanging around in your development enviornment.  I would recommend creating a new UIViewController class with a different name (BaseViewController or something to that effect), and see if you have the same issues.  I don't see anything in the code you've posted that should cause the kind of error you're seeing.

This was selected as the best answer
firechimpfirechimp

Hi Kevin,

Thanks for your reply, I tried your suggestion but it didn't have any effect.

 

I am going to try and rebuild from scratch and see if that helps, I will respond to this post after I have done this.

firechimpfirechimp

Hi Kevin,

Thanks for your help!

I rebuilt from scratch and it all worked ok, just looks like it may have had issues with me changing names around etc...