0

usersignin時にloginVCを却下しようとしています。単にユーザーの署名を許可します

if success {
dismiss(animated:true, completion:nil)
}

閉じた後、別のviewControllerのAuthVCである私のホームページが表示されます。

override func viewDidAppear(_ animated: Bool) {
                    super.viewDidAppear(animated)
                   
                    if Auth.auth().currentUser != nil {
                        self.dismiss(animated: true, completion: nil)
                    }
            

class LoginVC: UIViewController {
    
    @IBOutlet weak var emailField: InsetTxtField!
    
    @IBOutlet weak var pwdField: InsetTxtField!
    
    override func viewDidLoad() {
        super.viewDidLoad()
        emailField.delegate = self
        pwdField.delegate = self
        
    }
    @IBAction func signInBtnWasPressed(_ sender: Any) {
        if emailField.text != nil && pwdField.text != nil {
            AuthService.instance.loginUser(email: emailField.text!, andPassword: pwdField.text!) { (success, loginError) in
                if success {
                    print("login sucessfully")
                    self.dismiss(animated: true, completion: nil)
                    
                } else {
                    print(loginError!.localizedDescription)
                    
                }
                AuthService.instance.registerUser(email: self.emailField.text!, andPassword: self.pwdField.text!) { (success, registrationError) in
                    if success {
                        AuthService.instance.loginUser(email: self.emailField.text!, andPassword: self.pwdField.text!) { (success, nil) in
                             print("Successfully registered user")
                            self.dismiss(animated: true, completion: nil)
                        
                    }
                    }
                    else {
                        print(String(describing: registrationError?.localizedDescription))
                    }
                }
            }
            
        }
    }
     @IBAction func closeBtnWasPRessed(_ sender: Any) {
        dismiss(animated: true, completion: nil)
    }
}

今それが明らかになることを願っています。viewDidAppear 関数が呼び出されません。

4

1 に答える 1

0

モーダル ビュー コントローラーには、モーダル プレゼンテーション スタイルとして UIModalPresentationOverFullScreen があります。

親ビューが消えることはないため、viewDidAppear は呼び出されません。

これを処理するには、モーダル ビューを閉じるときに NSNotificationCenter にメッセージを投稿し、親ビュー コントローラーで処理します。

また

modalPresentationStyleLoginVCを次のように変更できます.fullScreen

viewController.modalPresentationStyle = .fullScreen

例 :

let nav = UINavigationController(rootViewController: LoginVC())
nav.modalPresentationStyle = .fullScreen
present(nav, animated: true, completion: nil) // if you add navigationController

or 

let vc = LoginVC()
vc.modalPresentationStyle = .fullScreen
present(nav, animated: true, completion: nil)
于 2020-06-17T06:34:32.960 に答える