导航控制器为零,尽管嵌入在视图控制器中

时间:2018-09-30 15:33:05

标签: ios swift uinavigationcontroller storyboard popviewcontroller

Storyboard

如您所见,我的导航控制器嵌入在根视图控制器中。在此视图控制器中,我有一个子视图,然后将弹出窗口推到视图控制器上。由于某些原因,我不能使用navigationController.popViewController(animated: true),因为导航控制器为nil(通过将值打印到调试控制台)。我该如何解决?

2 个答案:

答案 0 :(得分:1)

使用dismiss(animated flag: Bool, completion: (() -> Void)? = nil)。从弹出窗口视图控制器调用它:

self.dismiss(animated: true) 

答案 1 :(得分:0)

如果您从ViewController中显示弹出窗口

self.present(popover, animated: true, completion: nil)

您可以在弹出窗口中将其关闭

self.dismiss(animated: true) 

,如果您通过

将弹出式窗口推送到导航控制器
self.navigationController?.pushViewController(popover, animated: true)

您可以使用来关闭弹出窗口

self.navigationController?.popViewController(animated: true)