Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/39.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
ViewController关闭swift ios_Ios_Iphone_Swift_Uiviewcontroller - Fatal编程技术网

ViewController关闭swift ios

ViewController关闭swift ios,ios,iphone,swift,uiviewcontroller,Ios,Iphone,Swift,Uiviewcontroller,你好,我的英语不是很好,我提前道歉 我的申请有问题。场景如下:我将我的rootViewController分配给我的ViewController,这是我的开始。我还有其他的屏幕,是一个描述屏幕,我有两个登录和注册按钮,当预加载时会将我带到他们的控制器 现在,当我在日志全屏窗体上发送解雇命令时: 视图控制器注册 self.dismiss(animated: false, completion: nil) 所有正常视图都是隐藏的,但当进入前一个屏幕(即描述)时,如果已经有用户,我会进行验证,如果有

你好,我的英语不是很好,我提前道歉

我的申请有问题。场景如下:我将我的rootViewController分配给我的ViewController,这是我的开始。我还有其他的屏幕,是一个描述屏幕,我有两个登录和注册按钮,当预加载时会将我带到他们的控制器

现在,当我在日志全屏窗体上发送解雇命令时:

视图控制器注册

self.dismiss(animated: false, completion: nil)
所有正常视图都是隐藏的,但当进入前一个屏幕(即描述)时,如果已经有用户,我会进行验证,如果有解雇命令:

ViewController描述应用程序

self.dismiss(animated: false, completion: nil)
但它不执行该操作

代码

UIViewController

class ViewController: UIViewController {

    override func viewDidLoad() {

        FIRAuth.auth()!.addStateDidChangeListener() { auth, user in
            if user == nil {
                let descriptionController = DescriptionController()
                present(descriptionController, animated: true, completion: nil)
            }

        }
    }
}
class DescriptionController: UIViewController {

    @IBOutlet weak var sign_in_custom: UIButton!

    override func viewDidLoad() {

        FIRAuth.auth()!.addStateDidChangeListener() { auth, user in
            if user != nil {
               self.dismiss(animated: false, completion: nil)
            }

        }

        sign_in_custom.addTarget(self, action: #selector(changeToSingIn), for: [.touchUpInside])
    }

    func changeToSingIn() {
        let singInController = SingInController()
        present(singInController, animated: true, completion: nil)
    }
}
class SingInController: UIViewController {
    @IBOutlet weak var sign_in_custom: UIButton!
    override func viewDidLoad() {
        sign_in_custom.addTarget(self, action: #selector(singIn), for: [.touchUpInside])
    }
    func showLoad() {
        let alert = UIAlertController(title: nil, message: "Please wait...", preferredStyle: .alert)
        alert.view.tintColor = UIColor.black
        let loadingIndicator: UIActivityIndicatorView = UIActivityIndicatorView(frame: CGRectMake(10, 5, 50, 50) ) as UIActivityIndicatorView
        loadingIndicator.hidesWhenStopped = true
        loadingIndicator.activityIndicatorViewStyle = UIActivityIndicatorViewStyle.gray
        loadingIndicator.startAnimating();
        alert.view.addSubview(loadingIndicator)
        present(alert, animated: true, completion: nil)
    }
    func hideLoad() {
        self.dismiss(animated: false, completion: nil)
    }
    func singIn() {
        if (emailVarification()){
            if (passwordVarification()){
                showLoad()
                guard let email = emailTextField.text else { return }
                guard let password = passwordTextField.text else { return }
                FIRAuth.auth()?.createUser(withEmail: email, password: password) { (user, error) in
                    hideLoad()
                    if (user != nil) {
                        self.dismiss(animated: false, completion: nil)
                    } else {
                        let alert = UIAlertController(title: "Error", message: "This is a error", preferredStyle: UIAlertControllerStyle.alert)
                        alert.addAction(UIAlertAction(title: "Ok", style: UIAlertActionStyle.default, handler: nil))
                        self.present(alert, animated: true, completion: nil)
                    }
                }
            } else {
                let alert = UIAlertController(title: "Error", message: "This is a error", preferredStyle: UIAlertControllerStyle.alert)
                alert.addAction(UIAlertAction(title: "Ok", style: UIAlertActionStyle.default, handler: nil))
                self.present(alert, animated: true, completion: nil)
            }
        } else {
            let alert = UIAlertController(title: "Error", message: "This is a error", preferredStyle: UIAlertControllerStyle.alert)
            alert.addAction(UIAlertAction(title: "Ok", style: UIAlertActionStyle.default, handler: nil))
            self.present(alert, animated: true, completion: nil)
        }
    }
}
描述控制器

class ViewController: UIViewController {

    override func viewDidLoad() {

        FIRAuth.auth()!.addStateDidChangeListener() { auth, user in
            if user == nil {
                let descriptionController = DescriptionController()
                present(descriptionController, animated: true, completion: nil)
            }

        }
    }
}
class DescriptionController: UIViewController {

    @IBOutlet weak var sign_in_custom: UIButton!

    override func viewDidLoad() {

        FIRAuth.auth()!.addStateDidChangeListener() { auth, user in
            if user != nil {
               self.dismiss(animated: false, completion: nil)
            }

        }

        sign_in_custom.addTarget(self, action: #selector(changeToSingIn), for: [.touchUpInside])
    }

    func changeToSingIn() {
        let singInController = SingInController()
        present(singInController, animated: true, completion: nil)
    }
}
class SingInController: UIViewController {
    @IBOutlet weak var sign_in_custom: UIButton!
    override func viewDidLoad() {
        sign_in_custom.addTarget(self, action: #selector(singIn), for: [.touchUpInside])
    }
    func showLoad() {
        let alert = UIAlertController(title: nil, message: "Please wait...", preferredStyle: .alert)
        alert.view.tintColor = UIColor.black
        let loadingIndicator: UIActivityIndicatorView = UIActivityIndicatorView(frame: CGRectMake(10, 5, 50, 50) ) as UIActivityIndicatorView
        loadingIndicator.hidesWhenStopped = true
        loadingIndicator.activityIndicatorViewStyle = UIActivityIndicatorViewStyle.gray
        loadingIndicator.startAnimating();
        alert.view.addSubview(loadingIndicator)
        present(alert, animated: true, completion: nil)
    }
    func hideLoad() {
        self.dismiss(animated: false, completion: nil)
    }
    func singIn() {
        if (emailVarification()){
            if (passwordVarification()){
                showLoad()
                guard let email = emailTextField.text else { return }
                guard let password = passwordTextField.text else { return }
                FIRAuth.auth()?.createUser(withEmail: email, password: password) { (user, error) in
                    hideLoad()
                    if (user != nil) {
                        self.dismiss(animated: false, completion: nil)
                    } else {
                        let alert = UIAlertController(title: "Error", message: "This is a error", preferredStyle: UIAlertControllerStyle.alert)
                        alert.addAction(UIAlertAction(title: "Ok", style: UIAlertActionStyle.default, handler: nil))
                        self.present(alert, animated: true, completion: nil)
                    }
                }
            } else {
                let alert = UIAlertController(title: "Error", message: "This is a error", preferredStyle: UIAlertControllerStyle.alert)
                alert.addAction(UIAlertAction(title: "Ok", style: UIAlertActionStyle.default, handler: nil))
                self.present(alert, animated: true, completion: nil)
            }
        } else {
            let alert = UIAlertController(title: "Error", message: "This is a error", preferredStyle: UIAlertControllerStyle.alert)
            alert.addAction(UIAlertAction(title: "Ok", style: UIAlertActionStyle.default, handler: nil))
            self.present(alert, animated: true, completion: nil)
        }
    }
}
辛格勒

class ViewController: UIViewController {

    override func viewDidLoad() {

        FIRAuth.auth()!.addStateDidChangeListener() { auth, user in
            if user == nil {
                let descriptionController = DescriptionController()
                present(descriptionController, animated: true, completion: nil)
            }

        }
    }
}
class DescriptionController: UIViewController {

    @IBOutlet weak var sign_in_custom: UIButton!

    override func viewDidLoad() {

        FIRAuth.auth()!.addStateDidChangeListener() { auth, user in
            if user != nil {
               self.dismiss(animated: false, completion: nil)
            }

        }

        sign_in_custom.addTarget(self, action: #selector(changeToSingIn), for: [.touchUpInside])
    }

    func changeToSingIn() {
        let singInController = SingInController()
        present(singInController, animated: true, completion: nil)
    }
}
class SingInController: UIViewController {
    @IBOutlet weak var sign_in_custom: UIButton!
    override func viewDidLoad() {
        sign_in_custom.addTarget(self, action: #selector(singIn), for: [.touchUpInside])
    }
    func showLoad() {
        let alert = UIAlertController(title: nil, message: "Please wait...", preferredStyle: .alert)
        alert.view.tintColor = UIColor.black
        let loadingIndicator: UIActivityIndicatorView = UIActivityIndicatorView(frame: CGRectMake(10, 5, 50, 50) ) as UIActivityIndicatorView
        loadingIndicator.hidesWhenStopped = true
        loadingIndicator.activityIndicatorViewStyle = UIActivityIndicatorViewStyle.gray
        loadingIndicator.startAnimating();
        alert.view.addSubview(loadingIndicator)
        present(alert, animated: true, completion: nil)
    }
    func hideLoad() {
        self.dismiss(animated: false, completion: nil)
    }
    func singIn() {
        if (emailVarification()){
            if (passwordVarification()){
                showLoad()
                guard let email = emailTextField.text else { return }
                guard let password = passwordTextField.text else { return }
                FIRAuth.auth()?.createUser(withEmail: email, password: password) { (user, error) in
                    hideLoad()
                    if (user != nil) {
                        self.dismiss(animated: false, completion: nil)
                    } else {
                        let alert = UIAlertController(title: "Error", message: "This is a error", preferredStyle: UIAlertControllerStyle.alert)
                        alert.addAction(UIAlertAction(title: "Ok", style: UIAlertActionStyle.default, handler: nil))
                        self.present(alert, animated: true, completion: nil)
                    }
                }
            } else {
                let alert = UIAlertController(title: "Error", message: "This is a error", preferredStyle: UIAlertControllerStyle.alert)
                alert.addAction(UIAlertAction(title: "Ok", style: UIAlertActionStyle.default, handler: nil))
                self.present(alert, animated: true, completion: nil)
            }
        } else {
            let alert = UIAlertController(title: "Error", message: "This is a error", preferredStyle: UIAlertControllerStyle.alert)
            alert.addAction(UIAlertAction(title: "Ok", style: UIAlertActionStyle.default, handler: nil))
            self.present(alert, animated: true, completion: nil)
        }
    }
}

视图中使用此代码显示:

FIRAuth.auth()!.addStateDidChangeListener() { auth, user in
        if user != nil {
           self.dismiss(animated: false, completion: nil)
        }

    }

    sign_in_custom.addTarget(self, action: #selector(changeToSingIn), for: [.touchUpInside])

与其让DescriptionController自行关闭,更好的方法是通知ViewController用户已登录,并在必要时返回任何错误。然后,ViewController可以根据登录成功或失败执行所需的任何其他步骤。这可以通过使用委托模式实现(DescriptionController定义协议,ViewController实现协议)

这是因为第二个控制器基本上刚刚放置在现有控制器的顶部。第一个视图仍在第二个视图下运行,当第二个视图关闭时,第一个视图不会调用ViewDidLoad。因此,要解决这个问题,您可能需要将它添加到ViewDidDisplay函数中