我有一個Parse Sign Up,並且我有一個UIAlertController,我希望UIAlertController顯示一個指示符,但在註冊時出現錯誤時會被另一個UIAlertController取消。用另一個UIAlertController替換UIAlertController
我有幾種情況註冊失敗,所有工作之前添加指標的UIAlertController。指示提醒控制器在註冊成功並正確解除時工作正常。
//create an alert controller
let pending = UIAlertController(title: "Creating New User", message: nil, preferredStyle: .Alert)
//create an activity indicator
let indicator = UIActivityIndicatorView(frame: pending.view.bounds)
indicator.autoresizingMask = .FlexibleWidth | .FlexibleHeight
//add the activity indicator as a subview of the alert controller's view
pending.view.addSubview(indicator)
indicator.userInteractionEnabled = false // required otherwise if there buttons in the UIAlertController you will not be able to press them
indicator.startAnimating()
self.presentViewController(pending, animated: true, completion: nil)
下面是註冊代碼,這個工程
if signUpError == nil {
println("Sign Up Successful")
// Keep track of the installs of our app
var installation: PFInstallation = PFInstallation.currentInstallation()
installation.addUniqueObject("Reload", forKey: "channels")
installation["user"] = PFUser.currentUser()
installation.saveInBackground()
// to stop the uialertviewcontroller once sign up successful
pending.dismissViewControllerAnimated(true, completion: {
self.performSegueWithIdentifier("goToAppFromSignUp", sender: self)
})
}
這是我在哪裏卡住了,這只是其中一種情況下,如果我能得到這個工作,我能做到這一點爲其他人。
else {
println("Error Sign Up")
//If email has been used for another account kPFErrorUserEmailTaken
if(signUpError!.code == 203) {
let alertController = UIAlertController(title: "Sign Up Failed", message: "Sorry! Email has been taken! ", preferredStyle: .Alert)
let OKAction = UIAlertAction(title: "OK", style: .Default) { (action) in
// ...
}
alertController.addAction(OKAction)
self.presentViewController(alertController, animated: true) {
// ...
}
}
我的想法是駁回UIAlertController並顯示在完成塊
pending.dismissViewControllerAnimated(true, completion: {
self.presentViewController(alertController, animated: true) {
// ...
}
})
下一個,但應用程序凍結未決報警控制器(帶有指示燈)上。 這是已經介紹(null)
任何想法?謝謝。
在'其他'部分,您沒有關閉待處理的控制器。 –