Presenting modal viewcontroller over splitviewcont

2019-07-23 03:07发布

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.

1条回答
Emotional °昔
2楼-- · 2019-07-23 03:09

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;
查看更多
登录 后发表回答