• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

ios - UIBarButtonItem 取决于演示文稿。 swift 3

[复制链接]
菜鸟教程小白 发表于 2022-12-11 18:07:16 | 显示全部楼层 |阅读模式 打印 上一主题 下一主题

我遇到了一个问题,因为有两种方法可以显示我的 ViewController

  1. 第一种方法是 performSegue(withIdentifier: "segue", sender: self)

它工作得很好,因为我的 navigationItem 中有这个后退按钮:

enter image description here

  1. 然后我使用此代码呈现相同的 ViewController(来自另一个 viewController,而不是第一种情况):

        let storyboard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
        let navVC = storyboard.instantiateViewController(withIdentifier: "navViewController") as! UINavigationController
        let vc = navVC.topViewController as! ViewController             
        self.present(navVC, animated: true, completion: nil)
    

但是我的 ViewController 中没有任何后退按钮。

我的问题是:当我使用这个功能时,我怎样才能保留我的backButton(它是怎样的):performSegue(withIdentifier: "segue", sender: self) ,但是当我使用这个函数时添加按钮(可能看起来不同):self.present(navVC, animated: true, completion: nil)

注意: 在我的案例 1 中,我的 segue 直接连接到 ViewController ,但在案例 2 中,我展示了 UINavigationControllerViewController embed in 在这个 UINavigationController 中的。

编辑:我试过这段代码,但它总是打印:"1.........":

if self.presentingViewController != nil {
            print("1..........")
        } else if self.navigationController?.presentingViewController?.presentedViewController == self.navigationController  {
            return print("2.........")
        } else if self.tabBarController?.presentingViewController is UITabBarController {
            return print("3........")
        }

而且这段代码也会打印:"Else......." :

let isPresentingInAddMealMode = presentedViewController is UINavigationController

if isPresentingInAddMealMode {
    print("FirstOption......................")

} else {
    print("Else......................")

}

如果您需要更多信息,请告诉我。 非常感谢。



Best Answer-推荐答案


您需要检查presentedViewController 并添加返回按钮,如下所示。

if ([self presentedViewController]) {
        // add your back button item here
    }

关于ios - UIBarButtonItem 取决于演示文稿。 swift 3,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40763578/

回复

使用道具 举报

懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关注0

粉丝2

帖子830918

发布主题
阅读排行 更多
广告位

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap