Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I switch a new view controller in iOS development?

I am trying to write an IBAction to switch view controllers for my iPhone application:

-(IBAction)changeToView2:(id)sender 
{
    if (self.view2 == nil)
    {
        view2 = [[UIViewController alloc] initWithNibName:@"View2Controller" bundle:[NSBundle mainBundle]];
    }
    self.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
    [self presentedViewController: view2 animated:YES];
}

However, I am getting a build error noting that no interface declares "presentedViewController:animated:". Why?

Changing this to "presentViewController:animated:" produces the same error.

like image 921
Justin Copeland Avatar asked Jan 16 '23 19:01

Justin Copeland


2 Answers

The method is presentViewController:animated:completion:, not presentedViewController:animated:

like image 186
2 revs Avatar answered Jan 21 '23 14:01

2 revs


Instead of

[self presentedViewController: view2 animated:YES];

try

[self presentViewController: view2 animated:YES];
like image 33
Damo Avatar answered Jan 21 '23 12:01

Damo