将自定义目标分配给 popToRootViewController swift 4 [英] assigning a custom destination to popToRootViewController swift 4

查看:34
本文介绍了将自定义目标分配给 popToRootViewController swift 4的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 navigationController?.popToRootViewController(animated: true) 将当前视图关闭到上一个视图.我的视图控制器关系如下所示.

I am using navigationController?.popToRootViewController(animated: true) to dismiss my current view to the previous view. My view controller relationship looks like this.

VC1->VC2
VC1->VC3
VC3->VC2

每当客户端在 VC2 中时,我都想将导航控制器弹出回 VC1.当 rootviewcontroller 设置为 VC1 时,这可以正常工作.但是,当客户端使用 VC3 的 segue 进入 VC2 时,rootviewcontroller 设置为 VC3,导航控制器弹出到 VC3.

Whenever the client is in VC2 I want to pop the navigation controller back to VC1. This works fine when the rootviewcontroller is set to VC1. However, when the client uses a segue from VC3 to enter VC2, the rootviewcontroller is set to VC3 and the navigation controller pops to VC3.

我试图像这样更改 rootviewcontroller.

I tried to change the rootviewcontroller like this.

 // set root view controller
    let appdelegate = UIApplication.shared.delegate as! AppDelegate
    let mainStoryboard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
    let VC1 = mainStoryboard.instantiateViewController(withIdentifier: "VC1") as! FirstViewController
    appdelegate.window!.rootViewController = VC1
    navigationController?.popToRootViewController(animated: true)

但这实际上将视图控制器返回到根视图控制器(VC1),甚至在navigationController?.popToRootViewController(animated: true)"行之前执行,因此没有动画.

But this actually returns the viewcontroller to the root view controller (VC1) even before the line "navigationController?.popToRootViewController(animated: true)" is executed so there is no animation.

有没有办法设置导航控制器的根视图控制器而不立即显示根视图控制器?

Is there any way to set the rootviewcontroller of a navigation controller without presenting the root view controller right away?

推荐答案

如果你把 appdelegate.window!.rootViewController = VC1单独的控制器,因此您不能应用 popToRootViewController.

If you put appdelegate.window!.rootViewController = VC1, the stack of controllers has died, you only have in the stack an alone Controller, therefore you can't apply popToRootViewController.

如果这是您需要的导航,也许,这篇

If this is your required navigation, maybe, this post helps you:

这篇关于将自定义目标分配给 popToRootViewController swift 4的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆