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

时间:2023-01-23 22:38:32

I'm trying to make ViewController present after Modal dismiss

我试图在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)
})

But it will return "whose view is not in the window hierarchy!" maybe it's present a view after the controller dismissed

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

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

2 个解决方案

#1


2  

Notice the self in self.present, what you are doing, is basically tell the vc that you are dismissing to present a new vc, thats wrong way to do, the correct way is tell it's PARENT vc to present a new vc, by using delegate/unwind to call the parent vc to present new vc

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

#2


0  

You are using self. It means you are dismissing the current view controller. It should be the parent view controller who will present a new view controller.

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

#1


2  

Notice the self in self.present, what you are doing, is basically tell the vc that you are dismissing to present a new vc, thats wrong way to do, the correct way is tell it's PARENT vc to present a new vc, by using delegate/unwind to call the parent vc to present new vc

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

#2


0  

You are using self. It means you are dismissing the current view controller. It should be the parent view controller who will present a new view controller.

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