如何修复“错误视图不在窗口层次结构中!”

时间:2016-10-06 13:23:39

标签: ios swift swift3 viewcontroller

我有一个班级PopUpViewController,可以使用sharedInstance MessageController访问班级handleLogout()方法static let。但是当访问该方法并尝试呈现另一个视图控制器(loginController)时,我在控制台中收到此警告:

  

“错误视图不在窗口层次结构中!”

有人可以帮忙吗?

class PopUpViewController: UIViewController {
    lazy var logOutButton: UIButton = {
        let button = UIButton(type: .system)
        button.translatesAutoresizingMaskIntoConstraints = false
        button.setTitle("Logout", for: UIControlState())
        button.titleLabel?.font = UIFont.boldSystemFont(ofSize: 20)
        button.addTarget(self, action: #selector(logOut), for:.touchUpInside)
        button.tintColor = .white
        return button
    }()

    func logOut(){
        removeAnimate()
        MessageController.sharedInstance.handleLogout()
    }
    ...
}

MessageController

class MessageController: UITableViewController{
    static let sharedInstance = MessageController()

    func handleLogout(){
        do {
            try FIRAuth.auth()?.signOut()
        }catch let logoutError{
            print(logoutError)
        }
        // to je za ime na vrhu ob prijavi nastavi se vrednost
        let loginController = LoginController()
        loginController.messagesController = self
        GIDSignIn.sharedInstance().signOut() // google logout

        self.present(loginController, animated: false, completion: nil)
    }
}

0 个答案:

没有答案