您好我有以下情况:
|---> VC1----->|
VC_Home ->|---> VC2----->|------> VCm
|---> VC3----->|
VC1,VC2和VC3可以转到相同的ViewController(VCm)
如何从VCm导航回正确的Previous VC 如果我从VC1开始并转到VCm,则Vcm将返回VC1。 所以,VC2和VC3也一样。
所有VC1,VC2,VC3都不要嵌入NavigationController。
这能够识别哪一页是前一页吗?
@IBAction func goBack(_ sender: Any){
navigationController?.popViewController(animated: true)
}
请帮忙。
由于
答案 0 :(得分:0)
UINavigationController
storyBoard
UIViewController
[这是VC_HOME],并将其与UINavigationController
关联为root View Controller
(按住Ctrl +拖动)myHome
")go to vc1
,go to vc2
,go to vc3
],当然为每个按钮添加@IBAction
UIViewController
,并为步骤3添加ID myVc1
,myVc2
,myVc3
现在为@IBAction go to vc1
添加以下代码:
let view = storyboard!.instantiateViewController(withIdentifier: "myVc1")
navigationController?.pushViewController(view, animated: true)
为@IBAction go to vc2
添加以下代码:
let view = storyboard!.instantiateViewController(withIdentifier: "myVc2")
navigationController?.pushViewController(view, animated: true)
为@IBAction go to vc3
添加以下代码:
let view = storyboard!.instantiateViewController(withIdentifier: "myVc3")
navigationController?.pushViewController(view, animated: true)
现在,对于每个视图添加按钮,转到VC_M
,如上面的步骤
navigationController?.popViewController(animated: true)
navigationController?.popToRootViewController(animated: true)
答案 1 :(得分:0)
只是dismiss
你的最终视图控制器。在最终视图控制器中为您添加以下操作。
dismiss(animated: true, completion: nil)