2017-03-25 6 views
0

別のView Controllerにプッシュする際に問題があります。私は単純なログインシステムを作成しましたが、パスワードが間違っていてもデフォルトのView Controllerにプッシュされます。別のViewControllerを押す

注:ユーザー名とパスワードが有効な場合は、デバッグ領域に「ログイン」メッセージが表示されます。

+0

あなたはストーリーボードにsegueを追加しましたか?すべてのコードを投稿してください。 – ChanWarde

+0

@Abdullahより多くのコードを表示します。 –

+0

ボタンからの接続を削除し、クラス –

答えて

0

あなたはそれが直接、別のVCにセグエボタンをクリックすると、それが条件を確認する習慣例えば

enter image description here

ためのダイレクトボタンでセグエ接続を与えています。

あなたはストーリーボードのIDを使用している場合、VCとの間の接続を削除するには、直接direcltyクラス

を使用してセグエを指向

enter image description here

let storyBoard = UIStoryboard(name: "Main", bundle: nil) 

      let cameraVC = storyBoard.instantiateViewController(withIdentifier: "CameraViewController") as! CameraViewController 

      self.navigationController?.pushViewController(cameraVC, animated: true) 

接続にアクセスすることができます

enter image description here

[self performSegueWithIdentifier:@"identifierName" sender:self]; 

コール

else { 

      print ("Logged in") 
      performSegue(withIdentifier: "identifierName", sender: self) 

      } 
+0

作品はチャームのようです! 注:performSegue(withIdentifier: "identifierName"、送信者:self)はself.performSegue(withIdentifier: "identifierName"、送信者:自己)にする必要があります ありがとう、皆さんありがとう! – Abdullah

0

あなたはセグエを使用する場合それは、より良いような。まず、識別子を持つCameraViewControllerのセグを作成します。次に、コーディングでそれを呼び出します。

performSegue(withIdentifier: "mySegueID"、送信者:自己)

0

1)シンプルなストーリーボードからIBActionターゲットからコードを削除します。

2)ストーリーボード - >プロパティ - >識別子 - >ここで1つの識別子を設定して、あなたのセグを選択してください。

3)コードにこのデリゲートを追加します。

override func shouldPerformSegue(withIdentifier identifier: String, sender: Any?) -> Bool { 
     if identifier == "youridentifier" { 
      if username and password correct 
      { 
       return true 
      } 
      else 
      { 
       show alert here 
       return 
      } 
     } 
     return true 
    } 

シンプル!

関連する問題