1

Possible Duplicate:
How to create custom modal segue in 4.2 Xcode using storyboard

So I have a viewController that I want to push onto my current view controller modally. Here is the screenshot of my storyboard, with the view I'm trying to load highlighted: enter image description here

So I've created a segue between the current view and the second navigation controller, lets call it "alert". Because I don't have the segue tied to any sort of button, I'm just trying to load the view modally within the following if statement:

if([detector judgeSpeed:[ratio floatValue]])
{
    //push the new view here
}

How do I go about this? Do I need to implement some sort of delegate or the prepareForSegue method?

Cœur
  • 37,241
  • 25
  • 195
  • 267
Julian Coltea
  • 3,599
  • 10
  • 26
  • 32

4 Answers4

5

You could use a segue, but here's another alternative:

SomeViewController *controller = [self.storyboard instantiateViewControllerWithIdentifier:@"SomeIdentifier"];
[self.navigationController presentModalViewController:controller animated:YES]

Remember to set the identifier of the view controller in your storyboard.

More information and an example project here.

Community
  • 1
  • 1
matsr
  • 4,302
  • 3
  • 21
  • 36
  • 2
    After iOS 6, this is deprecated. Here's an updated version of the suggested solution. [self presentViewController:second animated:YES completion:NULL]; – Nick N Apr 10 '14 at 17:56
3

presentModalViewController is code for iOS 6 but I need code for iOS 9. Can anyone help?

Simon
  • 8,981
  • 2
  • 26
  • 32
ryudice
  • 36,476
  • 32
  • 115
  • 163
1

The answer's on How to create custom modal segue in 4.2 Xcode using storyboard should help.

T.J's answer:

UIViewController *src = (UIViewController *) self.sourceViewController;
[UIView transitionWithView:src.navigationController.view duration:0.5
                   options:UIViewAnimationOptionTransitionFlipFromTop
                animations:^{
                    [src.navigationController popToViewController:[src.navigationController.viewControllers objectAtIndex:0] animated:NO];;
                }
                completion:NULL];

tiguero's Answer:

[self.sourceViewController presentModalViewController:self.destinationViewController animated:NO];

Any of those answer's should answer this question as well.

Community
  • 1
  • 1
Aleksander Azizi
  • 9,829
  • 9
  • 59
  • 87
0

In the storyboard, create a segue from the Demo Video Capture View Controller to your new view controller by ctrl-dragging from the view controller itself to the new view controller. You do this by ctrl-dragging from the yellow button in the black bar below the Demo Video Capture View Controller to the new view. When it asks which kind select modal. Still in storyboard, click on the segue and identify it as "alert" in the identity navigator on the right. Now go to your .m file and use this implementation...

if([detector judgeSpeed:[ratio floatValue]])
{
   [self performSegueWithIdentifier:@"alert" sender:self];
}