2016-12-13 72 views
-4
@IBAction func signinButton(_ sender: AnyObject) { 
     self.ActivityIndicator.startAnimating() 

     let id = usernameTextField.text; 
     let pwd = passwordTextField.text; 

     if (id!.isEmpty || (pwd!.isEmpty)){ 
      let alert = UIAlertController(title: "Information!", message: "Username and Password is not empety", preferredStyle: UIAlertControllerStyle.alert) 
      alert.addAction(UIAlertAction(title: "Dismiss", style: UIAlertActionStyle.destructive, handler: nil)) 
      present(alert, animated: true, completion: nil) 
      self.present(alert, animated: true, completion: nil) 
     } 
} 

此錯誤: 警告:嘗試顯示其視圖不在窗口層次結構中的視圖!顯示新視圖控制器的控制檯警告

請幫助我..

+1

在這種情況下要做的第一件事是谷歌的錯誤信息。你有沒有做過,並嘗試在那裏給的建議?那裏有很多東西。 –

+0

你有目前的聲明兩次導致警報提交了兩次事件甚至在第一次完成之前,因此問題 –

+2

重複的'現在'行。 – vadian

回答

1

你有2種present功能。

present(alert, animated: true, completion: nil) 
self.present(alert, animated: true, completion: nil) 

到:所以剛剛從改變你的代碼

present(alert, animated: true, completion: nil) 
2

試試這個(只是刪除最後self.present行):

@IBAction func signinButton(_ sender: AnyObject) { 
     self.ActivityIndicator.startAnimating() 

     let id = usernameTextField.text; 
     let pwd = passwordTextField.text; 

     if (id!.isEmpty || (pwd!.isEmpty)){ 
      let alert = UIAlertController(title: "Information!", message: "Username and Password is not empety", preferredStyle: UIAlertControllerStyle.alert) 
      alert.addAction(UIAlertAction(title: "Dismiss", style: UIAlertActionStyle.destructive, handler: nil)) 
      present(alert, animated: true, completion: nil) 
     } 
} 
+0

這沒有奏效。 當我想按下按鈕登錄時,用戶名和密碼不在內容中。應顯示錯誤消息,但不顯示錯誤。直接進入菜單。 –

+0

我不認爲我明白你想要做什麼。使用此代碼時,如果id爲空或者pwd爲空**,則應該顯示警告**。嘗試在'let alert ...'行放置一個斷點,看它是否進入if語句。 – JPetric

0

如何使一個通知徽章。 如果在表格重新加載時有新的數據,則在這個tableview上顯示通知標誌。 enter image description here

相關問題