dismissViewControllerAnimated is called but ViewController is not dismissed

前端 未结 5 1642
旧巷少年郎
旧巷少年郎 2021-02-02 06:02

I am having a problems with the dismissViewControllerAnimated method not closing down the view.

What is happening in the app here is:

  • Cell in
相关标签:
5条回答
  • 2021-02-02 06:47

    Your Situation is - ItemViewController -> ItemDetailViewController (pushed on navigationController) Self.dismissViewController(..) dismiss a view controller that is presented over self(in ur case it is ItemViewController). Here, u did not presented any VC over self, instead u pushed a new VC over navigation stack. So, Correct way to dismiss ItemDetailViewController would be

    self.navigationController.popViewController(true). please read the description of dismissViewController(....) to get more clarity.

    0 讨论(0)
  • 2021-02-02 06:50

    Had a problem where calling dismissViewControllerAnimated dismissed the keyboard in a UIViewController, but not the view itself.

    Solved it by using two calls:

    [self dismissViewControllerAnimated:NO completion:nil];
    [self dismissViewControllerAnimated:YES completion:nil];
    

    an instant one for the keyboard, then an animated one for the controller

    0 讨论(0)
  • 2021-02-02 06:57

    What if you call [controller.navigationController popViewControllerAnimated:YES] instead?

    For that matter, what if you call [controller dismissViewControllerAnimated:YES completion:nil] instead of calling it on self?

    0 讨论(0)
  • 2021-02-02 06:57

    The answer is in this page: dismissviewcontrolleranimated-vs-popviewcontrolleranimated

    dismissViewController is used when you do not have a navigationcontroller. Most probably you are using a navigation controller, then use self.navigationController popViewController instead.

    Also take note of lemax his remark: use NULL, not nill for the completionhandler

    0 讨论(0)
  • 2021-02-02 07:05

    I had a problem in iOS5 where the standard completion callback was not allowing the view to completely dismiss (only the current pushed view of that modal)

    [controller dismissViewControllerAnimated:YES completion:^ {
         //
     }];
    

    Solution for iOS5 is to not have a callback:

    [controller dismissViewControllerAnimated:YES completion:nil];
    
    0 讨论(0)
提交回复
热议问题