5

I'm using a SplitViewController which can't be part of a navigation controller. I'm using SetRootViewController on an IBAction, which is fine, but it's not animated. Ideally I'd like to use the same animation as the Navigation Controller does (slide in from the left/right) but if that's not possible I'd like to use a consistent animation when ever I need to do this.

glenstorey
  • 5,134
  • 5
  • 39
  • 71
  • Can you give more detail about what you want? You want to have your UISplitViewController animate like UINavigationController push when and where? – Dries De Smet Mar 16 '12 at 08:22
  • The Svc is loaded from an ibaction on the first screen, a view controller after a user clicks a button. I want the Svc to animate in, either a push or cross-dissolve or something. – glenstorey Mar 16 '12 at 09:23

2 Answers2

5

I'm not sure about this, but I would suggest the following.

Set the UISplitViewController as your UIWindow's rootViewController. In the viewDidLoad, you make a presentModalViewController:animated: call with the button's UIViewController as modal. Make sure you don't animate it. This gives you the illusion that the modal view is the first you see when the app launches. When you push the button, you animate the button's UIViewController out with dismissModalViewControllerAnimated:. Now you can choose how to animate. One of your choices is cross disolve.

Dries De Smet
  • 876
  • 8
  • 16
  • That's a really creative solution, I'll give it a go and let you know how I get on. – glenstorey Mar 20 '12 at 21:12
  • This would work, and it's a great way of approaching the problem - so you get the correct answer - but I'm not sure if I'll actually use it. It feels a bit messy and breaks the intended design flow a bit; especially since the SVC is only used in one part of the app. – glenstorey Mar 20 '12 at 21:33
  • @Dries De Smet-- i tried what you suggested, i wrote the code to presentModalViewController:animated: in the ViewDidLoad of the Svc and dismissed it on btnClick.. but as the VC is dismissed and Svc is presented the Svc ViewDidLoad: is called again resulting to presentModalViewController:animated: being called, and the Vc is shown again. Am i doing something wrong. – Bonnie Jul 27 '12 at 06:00
2

Using iOS 5.0 you will be able to use presentViewController:animated:completion to present the SplitViewController from your initial rootViewController.

Prior iOS 5.0 your only chance is using the transitionFromView:toView:duration:options:completion method on the rootViewController's view, which means you will have some effort with passing several messages to your SplitViewController manually. iOS prior 5.0 does not support container ViewControllers.

But probably you want to rethink your design. You should set the SplitViewController as rootViewController initally. On App startup (or whenever you need to) you should present your LoginViewController modally. When the user logs in successfully, you hide your modal view with whatever animation you want to choose.

Since the SplitViewController is your main ViewController it should be the rootViewController of your application.

Ben-G
  • 4,996
  • 27
  • 33
  • Your solution is correct but I don't agree with design rethinking. What he's trying to do is absolutely logical. In many situation, your suggested solution wouldn't work. We use the same design - writing our own screen switching mechanism and our own split view controller (which is really really easy). – Sulthan Mar 19 '12 at 15:27
  • 1
    Thanks for your answer Ben-G. When I try [appDelegate.window setRootViewController:splitViewController]; [splitViewController presentViewController:splitViewController animated:YES completion:NULL]; I get the error 'Application tried to present a Split View Controllers modally .'. I'm guessing I'm using the wrong syntax somewhere? I agree with @Sulthan regarding the design decisions I've made, but thanks for the suggestion. – glenstorey Mar 19 '12 at 17:34
  • Regarding [link](http://stackoverflow.com/questions/2579861/split-view-controller-must-be-root-view-controller) the SplitViewController is a special case, not being allowed to present modally. Unfortunately you will either have to go with the alternative solution, or use the `transitionFromView:toView:` method, handling the message passing to the splitViewController on your own. – Ben-G Mar 20 '12 at 07:27