NavigationController实现返回第一个控制器

前端之家收集整理的这篇文章主要介绍了NavigationController实现返回第一个控制器前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

在第一个控制器中添加一个按钮

let shutDownBtn: UIButton!

分别添加以下代码

override func viewWillDisappear(_ animated: Bool) {
        super.viewWillDisappear(true)
        self.shutDownBtn.isHidden = true
    }

    override func viewWillAppear (_ animated: Bool) {
        super.viewWillAppear(true)
        shutDownBtn = UIButton.init()
        shutDownBtn.setTitle("关闭",for: .normal)
        shutDownBtn.setTitleColor(UIColor.black,for: .normal)
        //        shutDownBtn.setImage(UIImage.init(named: "compose_guide_icon_close_check"),for: .normal)
        shutDownBtn.frame = CGRect(x: self.view.bounds.width - 120,y: 0,width: 40,height: 40)

        shutDownBtn.addTarget(self,action: #selector(shutdown),for: .touchUpInside)

        self.navigationController?.navigationBar.addSubview(shutDownBtn)
        self.shutDownBtn.isHidden = false
    }

猜你在找的Swift相关文章