【问题标题】:After dismissModalViewControllerAnimated: my tabbar disappears在dismissModalViewControllerAnimated后:我的标签栏消失了
【发布时间】:2015-05-24 15:34:34
【问题描述】:

我有一个由三层视图控制器组成的应用程序:UITabBarController => UINavigationController => UIViewController。它们都是在代码中生成的,而不是使用 IB。根据通常的设计指南,标签栏位于底部。在我的 UIViewController 中,我使用此代码来呈现 modalViewController:

myModalVC = [[MyModalViewController alloc] init];
[self.navigationController presentModalViewController:myModalVC animated:YES];

这工作正常,模态视图控制器弹出并覆盖整个屏幕。

但是,当在模态视图控制器中按下按钮时,我会运行:

[self dismissModalViewControllerAnimated:YES];

模态视图控制器动画消失。但是我可以看到原始的 UIViewcontroller 视图,但标签栏完全消失了。我用谷歌搜索了很多,但我找不到任何有同样问题的人。

【问题讨论】:

  • 在 self.tabBarController 上执行 presentModalViewController 时是否观察到相同的行为?
  • 根本没有显示模态视图控制器。我也尝试过 self.navigationController.tabBarController presentModalViewController 也无法显示模态 VC。
  • 你可以使用 [self presentModalViewController:myModalVC animated:YES];无需通过导航控制器

标签: iphone cocoa-touch ios4


【解决方案1】:

您应该将模态视图控制器委托给您的父视图控制器。 [self dismissModalViewControllerAnimated:YES]; 应该由委托而不是模态视图本身来完成,父视图负责关闭模态视图。

【讨论】:

  • 我会给你答案,因为它为我指明了正确的方向。
  • @Robert Redmond 不确定这是否解决了您的标签栏问题
  • 谢谢。这修复了我在导航栏下出现的额外空间/间隙。
【解决方案2】:

实际上,我通过谷歌搜索找到了更多。我将标签栏控制器设置为应用程序委托的属性,当它呈现模态 vc 时,它会这样做

UIApplication *myApp = [UIApplication sharedApplication];
noIBAppDelegate*appDelegate = (noIBAppDelegate*)myApp.delegate;
[appDelegate.tabBarController presentModalViewController:myModalVC animated:YES];

然后它通过这段代码将其关闭

UIApplication *myApp = [UIApplication sharedApplication];
noIBAppDelegate*appDelegate = (noIBAppDelegate*)myApp.delegate;
[appDelegate.tabBarController dismissModalViewControllerAnimated:YES];

这修复了标签栏消失的问题。

【讨论】:

    【解决方案3】:

    试试

    [self.navigationController dismissModalViewControllerAnimated:YES];
    

    【讨论】:

    • 不幸的是,这并没有关闭模态视图控制器。
    【解决方案4】:

    感谢您的回答!我遇到了同样的问题,但我是用 Swift 写的,所以我想我会包括我从你的解决方案中找到的解决方案。我只需要使用这两行来解决问题。不需要其他任何东西。

    tabBarController?.presentViewController(viewController, animated: true, completion: nil)
    

    tabBarController?.dismissViewControllerAnimated(true, completion: nil)
    

    我还要提一下:tabBarController?.delegate = self, 在我的 NavigationController 的 viewDidLoad 函数中。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-02-27
      • 2018-01-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-03-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多