简体   繁体   English

调用dismissViewControllerAnimated但不解除ViewController

[英]dismissViewControllerAnimated is called but ViewController is not dismissed

I am having a problems with the dismissViewControllerAnimated method not closing down the view. 我遇到了dismissViewControllerAnimated方法没有关闭视图的问题。

What is happening in the app here is: 这里的应用程序发生了什么:

  • Cell in ItemViewController is selected. 选择了ItemViewController单元格。
  • View is push ed to ItemDetailViewController and details are sent through a delegate View 被推送到ItemDetailViewController ,细节通过委托发送
  • User selects 'done' and the event is sent via a delegate to be closed in ItemViewController 用户选择“完成”,并通过委托发送事件以在ItemViewController关闭

All of this works except for the View is not dismissed, there are no errors. 所有这些工作除了视图没有被解雇,没有错误。 Can anyone see what is wrong? 任何人都可以看到有什么问题?

- (void)itemDetailViewControllerDidFinish:(ItemDetailViewController *)controller
{
    NSLog(@"Controller: %@", controller);
    // Returns - Controller: <ItemDetailViewController: 0x6b68b60>

    [self dismissViewControllerAnimated:YES completion:nil];
}

What if you call [controller.navigationController popViewControllerAnimated:YES] instead? 如果你调用[controller.navigationController popViewControllerAnimated:YES]怎么办?

For that matter, what if you call [controller dismissViewControllerAnimated:YES completion:nil] instead of calling it on self? 那么,如果你调用[controller dismissViewControllerAnimated:YES completion:nil]而不是自己调用它会怎么样?

The answer is in this page: dismissviewcontrolleranimated-vs-popviewcontrolleranimated 答案在此页面中: dismissviewcontrolleranimated-vs-popviewcontrolleranimated

dismissViewController is used when you do not have a navigationcontroller. 当您没有navigationcontroller时,将使用dismissViewController。 Most probably you are using a navigation controller, then use self.navigationController popViewController instead. 很可能你正在使用导航控制器,然后使用self.navigationController popViewController。

Also take note of lemax his remark: use NULL, not nill for the completionhandler 另请注意lemax他的评论:使用NULL,而不是nill用于completionhandler

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) 我在iOS5中遇到了一个问题,标准完成回调不允许视图完全解除(只有当前推送的该模态视图)

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

Solution for iOS5 is to not have a callback: iOS5的解决方案是没有回调:

[controller dismissViewControllerAnimated:YES completion:nil];

Had a problem where calling dismissViewControllerAnimated dismissed the keyboard in a UIViewController, but not the view itself. 有一个问题,调用dismissViewControllerAnimated解除了UIViewController中的键盘,但不是视图本身。

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 键盘的瞬间,然后是控制器的动画

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). 你的情况是 - ItemViewController - > ItemDetailViewController(推送在navigationController上)Self.dismissViewController(..)解除一个通过self呈现的视图控制器(在你的情况下它是ItemViewController)。 Here, u did not presented any VC over self, instead u pushed a new VC over navigation stack. 在这里,你没有提供任何VC而不是自我,而是你在导航堆栈上推送了一个新的VC。 So, Correct way to dismiss ItemDetailViewController would be 所以,正确的解雇ItemDetailViewController的方法就是

self.navigationController.popViewController(true). self.navigationController.popViewController(真)。 please read the description of dismissViewController(....) to get more clarity. 请阅读dismissViewController(....)的说明以获得更清晰。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM