Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIStoryBoard get first view controller from ApplicationDelegate

I have a protocol that my ApplicationDelegate implements. I want to pass this to the first view controller defined in a story board. How do I get access to it from the method?

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
like image 373
Aran Mulholland Avatar asked Nov 06 '11 04:11

Aran Mulholland


People also ask

How do I make my view controller first?

Specifying the Initial View ControllerOpen Main. storyboard and select the Tab Bar Controller Scene. On the right, select the Attribute inspector. You'll find a checkbox named Is Initial View Controller.

How do I switch between view controllers?

Right-click the control or object in your current view controller. Drag the cursor to the view controller you want to present. Select the kind of segue you want from the list that Xcode provides.


1 Answers

I am not sure if I am understanding the question correctly I think you are asking how do you get the first viewController in a storyboard. To get this you call,

UIStoryboard *storybord = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
UIViewController *vc =[storybord instantiateInitialViewController];

Change the name of the storyboard to suit your name, MainStoryboard is just the default name. Hope this is what you were looking for.

Edit:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    UIStoryboard *storybord = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
    UIViewController *vc =[storybord instantiateInitialViewController];
    //set the delegate on the view controller that you have loaded
    // Override point for customization after application launch.
    return YES;
}
like image 111
Scott Sherwood Avatar answered Oct 12 '22 13:10

Scott Sherwood