3

I am having an issue with popViewController.

I use pushViewController to go to OrdersFormViewController

OrdersFormViewController *ordersFormViewController = [[OrdersFormViewController alloc] initWithNibName:@"OrdersFormViewController" bundle:nil];

[self.navigationController pushViewController:ordersFormViewController animated:YES];
[ordersFormViewController release];

From OrdersFormViewController I display a UIAlertView in viewDidLoad and call popViewController but this is not working.

UIAlertView* alertView = [[UIAlertView alloc]
                         initWithTitle:@"Error"
                         message:@"Error"
                         delegate:self
                         cancelButtonTitle:@"OK"
                         otherButtonTitles:nil];
[alertView show];
[alertView release];

[self.navigationController popViewControllerAnimated:YES];

The view is not "popped" from the navigationController but when pushing the standard back button in the navigation bar, only the navigation bar changes and not the actual view.

Does anyone have an idea why this is happening?

simonbs
  • 7,932
  • 13
  • 69
  • 115
  • You should wait till the user dismisses the alert. This makes less confusion to the user. –  Mar 29 '11 at 18:59
  • Good point! I implemented that and now it works. Thank you very much. I'm not sure what the policy is here. Maybe you should leave an answer which I can accept? – simonbs Mar 29 '11 at 19:04
  • I've made it an answer, but actually it was a suggestion about user experience. Glad it worked :) –  Mar 29 '11 at 19:08

5 Answers5

7

I had a similar problem I fixed it by using

[self.parentViewController.navigationController popViewControllerAnimated:YES];

Hope that helps.

Tony Million
  • 4,296
  • 24
  • 24
  • 1
    About the parentViewController: "Note that as of 5.0 this no longer will return the presenting view controller." :( – Mazyod Mar 19 '12 at 09:21
4

Not sure what you're trying to acomplish; but try adding it to viewDidAppear instead.

viewDidLoad may be getting called before you do the initial pushViewController call.

Wex
  • 4,434
  • 3
  • 33
  • 47
  • +1 You will definitely run into problems trying to pop a view controller before it has appeared. – devios1 Aug 25 '14 at 23:51
1

You should wait till the user dismisses the alert. This makes less confusion to the user.

You replied to my comment that it worked, for some magical reason I don't understand.

  • It worked for some reason. I am not sure either. If someone should see this thread in the future, the right approach seems to be to move it to `viewDidAppear`. This also works for me. – simonbs Mar 30 '11 at 05:18
0

You should do all this in the -viewDidAppear: method. When called here, the animation sequence is currently in progress, and you controller will not have actually been animated onscreen yet. Wait until you've animated on screen, then dismiss yourself.

Ben Gottlieb
  • 85,404
  • 22
  • 176
  • 172
0

If you created your project from master-detail template, remove the split view controller.

Display Name
  • 4,502
  • 2
  • 47
  • 63