ios 调用了dismissViewControllerAnimated 但ViewController 没有被解除

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8988992/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-30 16:27:56  来源:igfitidea点击:

dismissViewControllerAnimated is called but ViewController is not dismissed

iphoneobjective-ciosios4ios5

提问by Ad Taylor

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

我在使用dismissViewControllerAnimated不关闭视图的方法时遇到问题。

What is happening in the app here is:

应用程序中发生的事情是:

  • Cell in ItemViewControlleris selected.
  • View is pushed to ItemDetailViewControllerand details are sent through a delegate
  • User selects 'done' and the event is sent via a delegate to be closed in ItemViewController
  • 单元格输入ItemViewController被选中。
  • 视图被推送到ItemDetailViewController并通过委托发送详细信息
  • 用户选择“完成”并通过委托发送事件以关闭 ItemViewController

All of this works except for the View is not dismissed, there are no errors. Can anyone see what is wrong?

所有这些都有效,除了 View 没有被关闭,没有错误。任何人都可以看到有什么问题吗?

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

    [self dismissViewControllerAnimated:YES completion:nil];
}

回答by Nick Lockwood

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]而不是调用 self 呢?

回答by Leander

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

答案在这个页面: 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.

当您没有导航控制器时,使用dismissViewController。很可能您正在使用导航控制器,然后使用 self.navigationController popViewController 代替。

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

还要注意 lemax 他的评论:对完成处理程序使用 NULL,而不是 nill

回答by Danoli3

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 iOS5is to not have a callback:

iOS5 的解决方案是没有回调:

[controller dismissViewControllerAnimated:YES completion:nil];

回答by Cbas

Had a problem where calling dismissViewControllerAnimateddismissed 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

键盘的即时一个,然后控制器的动画

回答by Arya

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

你的情况是 - ItemViewController -> ItemDetailViewController(推送到导航控制器上) Self.dismissViewController(..) 关闭一个呈现在 self 上的视图控制器(在你的情况下它是 ItemViewController)。在这里,你没有在 self 上展示任何 VC,而是在导航堆栈上推送了一个新的 VC。因此,关闭 ItemDetailViewController 的正确方法是

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

self.navigationController.popViewController(true)。请阅读dismissViewController(....) 的描述以获得更清晰的信息。