【发布时间】:2015-04-22 09:18:09
【问题描述】:
我有一个 Parse Sign Up,我有一个 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)
有什么想法吗?谢谢。
【问题讨论】:
-
在 'else' 部分,您还没有关闭待处理的控制器。
标签: ios swift parse-platform uialertcontroller presentviewcontroller