我的应用程序在屏幕底部而不是在中间显示本地通知,因为其余时间都是如此。下面有一张图片显示了我的问题。我还在下面附加了我的代码以供参考。我创建了一个名为displayAlert的函数,因此不必为其他警报重复相同的代码。
有没有人有什么建议?
Picture
func displayAlert(title: String, message: String) {
var alert = UIAlertController(title: title, message: message, preferredStyle: .ActionSheet)
alert.addAction(UIAlertAction(title: "Okay", style: .Default, handler: nil))
self.presentViewController(alert, animated: true, completion: nil)
}
@IBAction func loginButton(sender: AnyObject) {
var seperated = emailLabel.text?.componentsSeparatedByString("@")
let username = seperated![0]
if emailLabel.text != "" && passwordLabel.text != ""
{
activityIndicator = UIActivityIndicatorView(frame: CGRectMake(0,0,50,50))
activityIndicator.center = self.view.center
activityIndicator.hidesWhenStopped = true
activityIndicator.activityIndicatorViewStyle = .Gray
view.addSubview(activityIndicator)
activityIndicator.startAnimating()
UIApplication.sharedApplication().beginIgnoringInteractionEvents()
PFUser.logInWithUsernameInBackground(username, password: passwordLabel.text!, block: { (user, error) -> Void in
self.activityIndicator.stopAnimating()
UIApplication.sharedApplication().endIgnoringInteractionEvents()
if user != nil
{
// Logged in!
self.performSegueWithIdentifier(self.loginSegue, sender: self)
}
else
{
// Failed loggin in
if let errorCode = error?.userInfo["error"] as? String
{
self.errorMessage = errorCode
}
self.displayAlert("Failed Log In", message: self.errorMessage)
}
})
}
else
{
displayAlert("Error", message: "Please enter your email and password!")
}
}
最佳答案
根据文档https://developer.apple.com/reference/uikit/uialertcontroller/1620092-init将preferredStyle: .actionSheet
更改为preferredStyle: .alert
以模态显示