0

I have a Navigation Controller in a storyboard set as the initial view. It calls one viewController, lets call it inititalViewCon. I want initialViewCon to modally segue to another viewController as soon as it loads.

So it would open the app, go to initialViewCon and then have a modal segue pop up. How would I accomplish this?

iamVishal16
  • 1,780
  • 18
  • 40
user3451350
  • 61
  • 2
  • 8
  • 1
    What have you tried? Have you reviewed the UIViewController documentation? - In particular you should look at `viewDidAppear`. If your modal view controller is in your storyboard you should also investigate `performSegueWithIdentifier` – Paulw11 Apr 12 '14 at 09:45
  • So I have to do it programmatically? By subclassing the ViewController? – user3451350 Apr 12 '14 at 15:49
  • Yes, you have to do this in code, which means you do have to subclass the view controller. – rdelmar Apr 12 '14 at 16:04
  • You always have to subclass `UIViewController` as this is where you have the code to process the interaction between the user and your data – Paulw11 Apr 12 '14 at 22:00

1 Answers1

0

I subclassed the UIViewController, the second one, which I know is against Apple's guidelines.

I added this method to the subclass:

- (IBAction)doneButton:(id)sender {
    [self dismissViewControllerAnimated:YES completion:nil];
}

It's kind of strange that you can initiate a modal segue from a storyboard but there's no way to dismiss it without subclassing the viewController.

AndrewSB
  • 951
  • 3
  • 11
  • 25
  • Why would you say that subclassing `UIViewController` is against Apple guidelines? – Paulw11 Apr 13 '14 at 05:44
  • And you can do it in storyboards by using an unwind segue – Paulw11 Apr 13 '14 at 07:43
  • @Paulw11 not subclassing the UIViewController, but giving control the second view controller to dismiss itself. Apple says to keep control with the first view controller – AndrewSB Apr 13 '14 at 16:11
  • Again, nothing wrong with that. Particularly in the case of a modal view controller - the view controller that is being presented will often know best when it's work is done. You could separate control out of all UIViewControllers into a controller class in a more pure MVC style, but you would still have to subclass the UIViewControllers with the subclass using a delegate pattern or completion block to notify the controller class that it should (or should potentially) be dismissed – Paulw11 Apr 13 '14 at 20:11