IOS Swift3.1 删除UIViewController

来源:互联网 发布:淘宝千牛包邮怎么设置 编辑:程序博客网 时间:2024/06/05 22:50

在某些情况下,我们需要删除VC,比如自定义的 启动画面后面一个登陆界面,这样这两个界面在等陆后就不再使用了。


 class VC1: UIViewController {


    override func viewDidLoad() {
        super.viewDidLoad()

        let lab :UILabel = UILabel(frame: CGRect(x: 10, y: 50, width: 100, height: 30))
        lab.text = "Lab1"
        
        self.view.addSubview(lab)
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
   
    override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
            let vc2 = VC2()
        
            let appDG = UIApplication.shared.delegate as! AppDelegate
            appDG.window?.rootViewController = vc2
    
          //  self.present( vc2, animated: true, completion: nil)
          //  self.removeFromParentViewController()

    }
}

原创粉丝点击