2016-07-05 1 views
0

私のHomeViewControllerには、セルがクリックされたときにアクティブなものと、join listというタイトルのバーボタンアイテムがクリックされたときのものがあります。バーボタンの項目をクリックすると、ユーザーがログインしているかどうかをチェックしたいと思います。ユーザーがログインしていない場合は、LoginViewControllerインターフェースを表示し、ログインしている場合はjoinViewControllerのインターフェースを表示します。私はjoinViewControllerに参加intemからCtrlキーを保持することにより、ストーリーボードから参加セグエを作成し、これはビューすぐに表示を消す

class LoginViewController: UIViewController { 
    @IBAction func dismissView(sender: AnyObject) { 
     self.dismissViewControllerAnimated(true, completion: nil) 
に却下する

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) { 

     if segue.identifier == "detail" { 
     var detailScene=segue.destinationViewController as! DetailViewController 
     if let indexPath=self.table.indexPathForSelectedRow{ 
      let selectedPerson=listPerson[indexPath.row] 
      detailScene.person=selectedPerson 
     }} 

     else 
     if segue.identifier == "join"{ 

      if !userLoggedIn{ 
       let vc : AnyObject! = self.storyboard!.instantiateViewControllerWithIdentifier("LoginViewController") 
       self.presentViewController(vc as! UIViewController, animated: true, completion: nil) 

      } 

     } 

     } 

すべてが正常に動作しているが、LoginViewControllerに私が追加され、IBAction私のコードです

ボタンをクリックすると、homeViewControlledではなくjoinViewControllerがロードされます。私は何をきれいにしたのですか?また、解除ボタンをどうやって修正できますか?

+0

あなたの 'HomeViewController'で' shouldPerformSegueWithIdentifier'をオーバーライドし、そこにログインロジックを移動することができます。ログインしていなければ 'false'を返し、そうでなければ' true'を返します。お役に立てれば。 – riik

答えて

0

segueのどちらを表示するかを動的に選択する場合は、UIBarButtonItemに設定しないでください。私の提案は、からLoginViewControllerJoinViewControllerの2つのsegueをとjoinSegueという名前でドラッグすることです。

UIBarButtonItemよりをHomeViewControllerに作成してください。コードでは、次のようになります。

@IBAction func barButtonItemPressed(sender: AnyObject) { 
    if userLoggedIn { 
    self.performSegueWithIdentifier("joinSegue", sender: self) 
    } else { 
    self.performSegueWithIdentifier("loginSegue", sender: self) 
    } 
} 

私はあなたが解消ボタンについて何を求めているのかは分かりません。しかし、prepareForSegueを上書きして、UIViewControllerをこの段階で提示するかどうかを選択することはできません。既にUIViewControllerを提示する予定です。

関連する問題