ios - ViewController 关闭 swift ios

标签 ios iphone swift uiviewcontroller

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

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

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

ViewController注册

self.dismiss(animated: false, completion: nil)

一切正常, View 是隐藏的,但是当进入上一个描述屏幕时,如果有解散命令,我会验证是否已经有用户:

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)
            }

        }
    }
}

描述 Controller

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)
    }
}

输入 Controller

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)
        }
    }
}

sequence

最佳答案

这是因为第二个 Controller 基本上只是放在现有 Controller 的顶部。第一个 View 仍在第二个 View 下运行,当第二个 View 被关闭时,第一个 View 不会调用 ViewDidLoad。所以要解决它,您可能想将它添加到 ViewDidAppear 函数中。

关于ios - ViewController 关闭 swift ios,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43007203/

相关文章:

iphone - 重复的 UIView

ios - 在 Swift 中停止和启动 NSThread

ios - 从 application(.... launchOptions : [NSObject: AnyObject]? ) 处的 launchOptions 获取值

iphone - 如何让我的固定宽度移动网站始终出现 "fully zoomed in"?

ios - 在 iOS7 中总是无法访问

ios - 在 Xcode 6.1 及更高版本中创建项目时,屏幕在 iOS 7 中缩小

ios - 在 iOS 中出现键盘时滑动 UIView

ios - 无法将iOS应用正确添加到我的Firebase项目中

ios - WKWebView:是否可以预加载多个 URL?

ios - 当collectionview水平滚动时,如何确定选择了哪个tableView Cell