self.navigationController?.popToRootViewController(animated: true) 不会关闭任何呈现的视图控制器

弗雷德里克·布拉默

我正在 Xcode 中使用 Swift 和 Storyboard 开发一个应用程序。2 个视图控制器彼此重叠显示,我想通过按一个按钮来关闭它们。我已经在 StackOverflow 上搜索了答案,我找到了self.navigationController?.popToRootViewController(animated: true),但没有用。你对为什么这行不通有什么想法吗?

解决方案:

在这种情况下起作用的只是使用另一行代码。我不知道有什么不同,但它以某种方式起作用:

self.view.window!.rootViewController?.dismiss(animated: true, completion: nil)
贾瓦德·阿里

检查您的 NavigationController 是否为零 ...

if let nav = self.navigationController {
     nav.popToRootViewController(animated: true)
} else {
   print("nav is nil")
}

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

iOS9 self.canDisplayBannerAds = true不显示任何广告

为什么self.navigationController在viewDidLoad中为null?

[self.navigationController popToViewController:VC2 animation:NO]; 崩溃

dismissViewControllerAnimated()不会关闭视图控制器

self.navigationController?.popViewController从UIAlertController动画

Swift-self.navigationController转换后为nil

Swift-将self.navigationController调用到自定义单元格类中

NavigationController不会从功能调用+ Swift中推送

如何检查控制器是否已经在NavigationController ViewController堆栈上?

self.navigationController?.pushViewController无法正常工作

在呈现的视图控制器中的popToRootViewControllerAnimated之后未调用navigationController:willShowViewController:animated:

jonkyking / SlideMenu'尝试推送视图控制器..its navigationController == nil'

在容器视图中嵌入NavigationController

如何将新的视图控制器推送到tabbarcontroller中当时存在的NavigationController?

在[self.navigationController popToRootViewControllerAnimated:YES]期间分配变量;

popToRootViewControllerAnimated不执行任何操作,无法使应用程序返回首页

popToRootViewControllerAnimated之后崩溃

使用通用情节提要板时,dismissViewController不会关闭呈现的视图控制器

self.navigationController.topViewController作为HomeViewController

tabBar:didSelectItem和popToRootViewControllerAnimated

快速访问NavigationController子视图的项目

self.navigationController pushViewController:动画:给我黑屏

self.definesPresentationContext = true:导致黑屏吗?

Swift-self.navigationController为零

具有NavigationController作为根目录的iOS,仅一个控制器为横向

self.navigationController始终使用故事板到故事板导航返回nil

在导航控制器中取消分配具有 self 引用的视图控制器

视图控制器不会立即关闭并呈现新的视图控制器

在没有 NavigationController 的情况下关闭推送视图控制器