如何关闭导航控制器中的视图控制器,而不关闭整个堆栈 [英] How to dismiss a view controller in a navigation controller, without dismissing the whole stack

查看:34
本文介绍了如何关闭导航控制器中的视图控制器,而不关闭整个堆栈的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

基本上我有两个标签的标签栏控制器,每个标签都有一个单独的导航控制器,每个都有几个视图(见下文).

Basically I have tab bar controller with two tabs, each holds a separate navigation controller, each with a couple of views (see below).

在顶部"导航控制器(在右侧选项卡中),我可以选择一个图像,然后被带到最右边的屏幕预览图像...

In the "top" navigation controller (held in the right tab), I can choose an image, and then am taken to the rightmost screen to preview the image...

func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
    if let image = info[UIImagePickerControllerEditedImage] as? UIImage {

        let previewController = self.storyboard?.instantiateViewController(withIdentifier: "previewVC") as! PreviewViewController
        previewController.img = image
        previewController.navigationItem.setHidesBackButton(true, animated: false)
        self.navigationController?.pushViewController(previewController, animated: true)

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

...我点击发布"的地方.这将上传图像并调用 self.tabBarController?.selectedIndex = 0

...where I tap "post". This uploads the image and calls self.tabBarController?.selectedIndex = 0

这只是将我带到图像源,它位于底部"导航控制器(左侧选项卡)中.到现在为止还挺好.但是,当我需要在发布后显示上传屏幕时,预览屏幕仍然显示在右侧"选项卡中.

That simply takes me to the image feed, which is in the "bottom" navigation controller (left tab). So far so good. However, the preview screen is still displayed in the "right" tab, when I need the upload screen to be displayed after I post.

如果我在点击 post 时调用 self.dismiss(animated: true, completion: nil),整个导航控制器都会被关闭,我会被带回登录屏幕.

If I call self.dismiss(animated: true, completion: nil) when I tap post, the entire navigation controller is dismissed and I'm taken back to the login screen.

所以我试图关闭预览控制器,以便上传控制器显示为右侧选项卡中的默认视图,而不关闭该导航控制器中的整个堆栈.

So I'm trying to dismiss the preview controller so the upload controller is shown as the default view in the right tab, without dismissing the entire stack in that navigation controller.

我该怎么做?

推荐答案

如果您使用 导航控制器 要将视图控制器添加到导航堆栈(推送),您可以通过调用 pop 函数删除它们.当您以模态方式呈现视图控制器时,您可以调用dismiss 来移除视图控制器.

If you use navigation controllers to add view controllers to the navigation stack (push), you can remove them by calling a pop function. When you present view controllers modally, you call dismiss to remove the view controller.

这篇关于如何关闭导航控制器中的视图控制器,而不关闭整个堆栈的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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