1

I'm building an application now, 95% of the app is based around a SplitViewController, which loads the tableView content from a string from another view controller. Right now I got the initial view controller as the SplitViewController, but once I change it this code causes issues in my AppDelegate.m:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    // Override point for customization after application launch.
    UISplitViewController *splitviewController = (UISplitViewController *)self.window.rootViewController;
    UINavigationController *navigationController = [splitviewController.viewControllers lastObject];
    splitviewController.delegate = (id)navigationController.topViewController;
    return YES;
}

If I remove it, the SplitViewController doesn't work as supposed obviously. I tried this, just to see if everything else would work; the new initial view controller loaded successfully - but once I pressed a button to modal over to the SplitViewController again, this code is blamed with the following message:

#import <UIKit/UIKit.h>

#import "AppDelegate.h"

int main(int argc, char * argv[])
{
@autoreleasepool {
    return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
}
}

Exception
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Application tried to present a Split View Controllers modally .'

Any idea on how to fix this? Help will be highly appreciated!

Edit:

I found this: Set your splitView as the rootView of your app, present modally your singleView at launch, and whenever you want just dismiss it to let the splitView have control. Will have the same effect than having your singleView presenting the splitView.

And that's what I thought as well. Is this a viable solution and will apple approve it during testing?

user3653447
  • 19
  • 1
  • 6
  • This line of code `splitviewController.delegate = (id)navigationController.topViewController;` may be is causing your issue. As far as I can see this is not setting you `splitViewController`s delegate in anyway. Try assigning your `delegate` in your `viewController` instead of in the `AppDelegate` – Pancho May 19 '14 at 16:30

1 Answers1

0

The problem is that you can't segue to a SplitViewController. Unfortunately, the whole app would need to be based around the SplitViewController you have, or you'll need to recreate the app without the controller.

See this question for more information.

Community
  • 1
  • 1
Eichhörnchen
  • 592
  • 2
  • 12
  • 27
  • oh, that's really bad. Isn't there any way to segue to a SplitViewController? Could a solution be to navigate to the other View Controller upon launch and then closing that, navigating "backwards"? – user3653447 May 19 '14 at 17:08
  • I'm not 100% sure what you mean by that, but the documentation states `A split view controller must always be the root of any interface you create.` – Eichhörnchen May 19 '14 at 17:18
  • Instead of having a initial view controller not splitview, you make the splitview initial, but navigate to the fake initial upon launch. On the viewDidLoad method. So that it would appear the other viewcontroller is initial, even though the splitview is – user3653447 May 19 '14 at 17:27
  • My app has a project view (the new "initial" viewcontroller) and once the user selects a project it should open the SplitViewController – user3653447 May 19 '14 at 17:37
  • I did what I (tried to) explain ;) - and it actually turned out to work really well :) – user3653447 May 19 '14 at 18:05
  • Ah, alright! Sounds a little hacky - not sure what Apple will say about it. Good luck! – Eichhörnchen May 19 '14 at 19:22
  • I couldn't recreate my whole app, but this solution went nicely - and the animations look very good on the device ;) Thanks! – user3653447 May 19 '14 at 19:26
  • Don't you think Apple will approve it if the app functions the way it's supposed to? – user3653447 May 19 '14 at 19:45
  • I should hope so! Honestly I'm not too familiar with how their approvals go – Eichhörnchen May 19 '14 at 19:48