开发者

Why can't a UISplitViewController be the rootViewController property of a UIWindow?

开发者 https://www.devze.com 2023-03-30 17:24 出处:网络
When creating the initial view in开发者_运维知识库 iPhone applications you can set the IBOutlet rootViewController property of the main UIWindow to your default view controller, but this doesn\'t work

When creating the initial view in开发者_运维知识库 iPhone applications you can set the IBOutlet rootViewController property of the main UIWindow to your default view controller, but this doesn't work with a UISplitViewController.

If I do this I don't receive any compile errors, and the app runs, but no screen is displayed on app startup.

The way recommended by the Apple docs for UISplitViewController is to do the following within your app delegate launch method:

[window addSubview:splitViewController.view];

I was just wondering why UISplitViewController needed this different approach.


Of course that works. In fact, it's what the Split View-based Application template from Xcode 4.0.2 does (SDK 4.3).

Split view controllers are only intended for iPad, not iPhone, though. Are you trying this on an iPhone project?

Update

Since iOS 8 it is available on all devices.


Are you sure it isn't possible? rootViewController needs to be an UIViewController and UISplitViewController is an UIViewController. Try restarting Xcode. If that's not working, there's a big chance it's a bug, so I'ld suggest you file it at Apple's bug reporter.


I dont have any problems making a UISplitViewController UIWindow rootViewController. In fact, the Split View app template generates code that configures the app this way.


DLog(@"Method: homeScreenViewController");
        
    UISplitViewController *svc = (UISplitViewController*)[self.storyboard instantiateViewControllerWithIdentifier:@"HomeViewiPad"];

    //[self presentViewController:svc animated:YES completion:nil];
    
    UIWindow *window = [[[UIApplication sharedApplication] windows] objectAtIndex:0];
    window.rootViewController = svc;
    [window makeKeyAndVisible];
    
    /*
    for (UIWindow *window in [[UIApplication sharedApplication] windows])
    {
        if ([window screen] == [UIScreen mainScreen])
        {
            window.rootViewController = svc;
            //UIViewController *con =  [self.storyboard instantiateViewControllerWithIdentifier:@"HomeiPad"];
            //[window addSubview:con.view];
            [window makeKeyAndVisible];
        }
    }
     */

//vKj

0

精彩评论

暂无评论...
验证码 换一张
取 消