Search code examples
iosipadios6uisplitviewcontrollermodalviewcontroller

Presenting modal viewcontroller over splitviewcontroller at app startup


Due to the need for UISplitViewController to be rootviewcontroller, I am trying instead to present a viewcontroller modally at app startup to act as a login/welcome screen for the user. Apparently the following code in my AppDelegate.m should do the trick with IOS 6:

#import "AppDelegate.h"
#import "WelcomeViewController.h"

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.

WelcomeViewController *modalWelcomeView = [[WelcomeViewController alloc] initWithNibName:@"Welcome" bundle:nil];
[modalWelcomeView setModalPresentationStyle:UIModalPresentationFullScreen];
[self.splitViewController presentViewController:modalWelcomeView animated:NO Completion:nil];

return YES;
}

yet I get a "Property 'splitViewController' not found on object of type 'AppDelegate'" for the line above return YES;. I fear I'm doing something silly...

Any suggestions? Many thanks.


Solution

  • Alas I found the solution, actually required a slightly different approach in AppDelegate.m

    #import "AppDelegate.h"
    #import "WelcomeViewController.h"
    
    @implementation AppDelegate
    
    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    {
    // Override point for customization after application launch.
    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
    WelcomeViewController *modalWelcomeView = [storyboard instantiateViewControllerWithIdentifier:@"Welcome"];
    [self.window makeKeyAndVisible];
    [self.window.rootViewController presentViewController:modalWelcomeView animated:NO completion:NULL];
    
    return YES;