Ios – UIStoryBoard get first view controller from ApplicationDelegate

ios, ios5, uistoryboard

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

Best Solution

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;}