2016-12-13 3 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

このような状況で最初に行うことは、Googleにエラーメッセージです。あなたはそれをして、そこに与えられたアドバイスを試しましたか?そこにたくさんのことがあります。 –

+0

あなたは、警告が最初のものが完了する前であっても2度表示されるようにするために現在のステートメントを2回持っています。したがって、問題 –

+2

の 'present'行が重複しています。 – 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

関連する問題