2016-02-20 22 views
0

我的應用程序在屏幕底部顯示本地通知,而不是在中間,因爲它們是其餘時間。我在下面有一張照片顯示我的問題。我也附上了我的代碼以供參考。我創建了一個名爲displayAlert的函數,因此我不必爲其他警報重複相同的代碼。Swift 2:在屏幕底部而不是中間的本地通知

有沒有人有任何建議?

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!") 
    } 
} 
+3

顯示您正在使用顯示通知 – Wain

+1

看起來不像本地通知我的代碼。 – tktsubota

+0

這個視圖控制器是另一個視圖控制器的孩子嗎?它的觀點框架是什麼? – Wain

回答