gpt4 book ai didi

ios - 在 Parse (SWIFT) 上保存数据时打开弹出 View

转载 作者:行者123 更新时间:2023-11-30 12:19:36 25 4
gpt4 key购买 nike

我正在 Swift 上为应用程序创建一个注册 View 。我想在用户成功注册时加载弹出 View 以添加更多数据。我使用 Parse 存储数据。

我使用此代码来保存数据:

@IBAction func registerButtonPressed(_ sender: Any) {

if emailTextField.text == "" || usuerTextField.text == "" || password1TextField.text == "" || password2TextField.text == "" {

createAlert(title: "Error", message: "Fill all data")

} else {

if password1TextField.text != password2TextField.text {

createAlert(title: "Error", message: "Passwords must be the same")
} else {

activityIndicator = UIActivityIndicatorView(frame: CGRect(x: 0, y: 0, width: 50, height: 50))
activityIndicator.center = self.view.center
activityIndicator.hidesWhenStopped = true
activityIndicator.activityIndicatorViewStyle = UIActivityIndicatorViewStyle.gray
view.addSubview(activityIndicator)
activityIndicator.startAnimating()
UIApplication.shared.beginIgnoringInteractionEvents() // UIApplication.shared() is now UIApplication.shared

let user = PFUser()

user.username = usuerTextField.text
user.email = emailTextField.text
user.password = password1TextField.text

let acl = PFACL()

acl.getPublicWriteAccess = true

user.acl = acl

user.signUpInBackground(block: { (success, error) in

self.activityIndicator.stopAnimating()
UIApplication.shared.endIgnoringInteractionEvents() // UIApplication.shared() is now UIApplication.shared

if error != nil {

var displayErrorMessage = "Please try again later."

let error = error as NSError?

if let errorMessage = error?.userInfo["error"] as? String {

displayErrorMessage = errorMessage

}

self.createAlert(title: "Signup Error", message: displayErrorMessage)

} else {


}


})
}
}

在 else 语句中,我想添加以下代码:

    let vc = (
storyboard?.instantiateViewController(
withIdentifier: "sbPopUpID")
)!
vc.modalTransitionStyle = .crossDissolve
present(vc, animated: true, completion: nil)

但只有在 viewDidLoad 和 didReceiveMemoryWarning 之后加载它才有效,如果保存用户数据没有错误,我如何加载这个弹出窗口?

谢谢

最佳答案

您的代码看起来不错,您只是忘记在某些语句之前添加隐式 self 声明(调试器默认情况下应建议您这样做)。试试这个:

let vc = self.storyboard!.instantiateViewController(withIdentifier: "sbPopUpID")
vc.modalTransitionStyle = .crossDissolve
self.present(vc, animated: true)

关于ios - 在 Parse (SWIFT) 上保存数据时打开弹出 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44958214/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com