4

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.

3
  • Interestingly, XCode still notes that "no visible @interface declares the selector presentViewController:animated:" if I use that instead. Also, when I begin typing the function name, auto-complete does not mention this function name. Commented Apr 30, 2012 at 19:38
  • Also, what is 'completion:<#^(void)completion#>'? It seems as if this function has a third argument. Commented Apr 30, 2012 at 19:42
  • 1
    Is this code part of a view controller class? Or a view? Is the project navigation based? i.e. is there a navigationController? Commented May 1, 2012 at 7:26

4 Answers 4

7

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

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you, but XCode still notes that "no visible @interface declares the selector presentViewController:animated:".
1

Instead of

[self presentedViewController: view2 animated:YES];

try

[self presentViewController: view2 animated:YES];

1 Comment

Thank you, but XCode still notes that "no visible @interface declares the selector presentViewController:animated:".
1
[self presentViewController:view2 animated:YES];

3 Comments

Thank you, but XCode still notes that "no visible @interface declares the selector presentViewController:animated:".
Is "self" a UIViewController?
Can you go to your header file and post the interface here?
0

Try this your edited code.I think this will be helpful for you.

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.