31

I want to know what is the different of them. when I can call

[self dismissViewControllerAnimated:YES completion:nil];

and when I should call

[self.navigationController popViewControllerAnimated:YES];

according document of apple: dismissViewControllerAnimated means "Dismisses the view controller that was presented by the receiver." But I always fail to dismiss view controller by this method.

Pfitz
  • 7,336
  • 4
  • 38
  • 51
kevin young
  • 941
  • 2
  • 10
  • 22
  • 1
    As for dismiss see [this](https://youtu.be/oTsg-uJfxD4?t=556) video from Stanford. dismissViewController should always be sent to *presenting* viewController. If you send it the *presented* viewController and the presentedViewcontroller had not presented **a**nother viewController *then* it would dismiss it properly otherwise it would not do it right – mfaani Sep 29 '16 at 19:04

2 Answers2

41

-dismissViewControllerAnimated:completion:

Used to dismiss an UIViewController, which was presented by the method:

-presentViewController:animated:completion:.

-popViewControllerAnimated:

Method of UINavigationController is used to pop a controller shown by

-pushViewController:animated method of UINavigationController.

In the first case the view controller's view shows as a modal controller (usually from bottom to top), and the second case you are pushing a view controller in the navigation stack of UINavigationController.

Rudolf Real
  • 1,948
  • 23
  • 27
graver
  • 15,183
  • 4
  • 46
  • 62
39

your selected application is navigation based application means

[self.navigationController popViewControllerAnimated:YES];

your selected application is other than the navigation based application means

[self dismissViewControllerAnimated:YES completion:nil];
Senthilkumar
  • 2,471
  • 4
  • 30
  • 50
  • so does it means: I should not use dismissViewControllerAnimated in a navigation based application ? I think it is the reason why I always fail to dismissViewControllerAnimated, thank you ! – kevin young Jun 18 '12 at 09:34