Swift如何在解除模态后在根导航中显示视图

时间:2016-11-09 07:41:21

标签: ios swift uiviewcontroller uinavigationcontroller

我正试图在Modal解雇后使ViewController存在

let storyboard = UIStoryboard(name: "Main", bundle: nil)
let chatRoomVC = storyboard.instantiateViewController(withIdentifier: "ChatRoomVCId") as! ChatRoomVC
chatRoomVC.hidesBottomBarWhenPushed = true
chatRoomVC.passValue = passValue

self.dismiss(animated: true, completion: {
    self.present(chatRoomVC, animated: true, completion: nil)
})

但它将返回“其视图不在窗口层次结构中!”也许在控制人员解雇后,它会出现一个视图

The flow I suppose

3 个答案:

答案 0 :(得分:2)

注意self中的self.present,你正在做什么,基本上是告诉vc你正在解雇提出一个新的vc,这是错误的做法,正确的方法就是告诉它是PARENT vc提出一个新的vc,通过使用delegate / unwind来调用父vc来呈现新的vc

答案 1 :(得分:0)

你正在使用自己。这意味着您正在关闭当前视图控制器。它应该是将呈现新视图控制器的父视图控制器。

答案 2 :(得分:0)

从“ Controller_A”到“ Controller_B”->出现时,如下所示

--- View Controller A ---

self.navigationController?.present(Controller_B, animated: true, completion: nil)

当您要关闭“ Controller_B”并使用导航控制器显示“ Controller_C”时

--- View Controller B ---

let presenController : UINavigationController = self.presentingViewController as! UINavigationController

presentingController.dismiss(animated: true, completion: {
  presenController.pushViewController(Controller_C, animated: true)
})