2017-02-26 7 views
0

私はUIAlertを生成しました。これをリンクして新しいviewControllerを開きたいと思います。私は私が持っている異なるviewcontrollersのそれぞれの新しいファイルを追加し、クラスをリンクしている。新しいViewControllerに行くUIAlertController

私が持っているコードは、基本的には、ユーザーが、私は新しいのViewControllerは、とポップアップ表示したい「OK」クリックしたときに正しい答えをユーザーがクリックするアラートが、その後ポップアップしますとき。..

@IBAction func CorrectButton(_ sender: UIButton) { 

    let refreshAlert = UIAlertController(title: "Correct Answer", message: "Congratulations", preferredStyle: UIAlertControllerStyle.alert) 

    let vc = ThirdViewController() 

    refreshAlert.addAction(UIAlertAction(title: "Ok", style: .default, handler: { (action: UIAlertAction!) in self.present(vc, animated: true, completion: nil) 

    })) 

    present(refreshAlert, animated: true, completion: nil) 
} 

ですアプリの次の部分。現在起こっているのは、画面が黒くなっているアラートメッセージの「ok」をクリックしたときだけです。

任意の助けをいただければ幸いです..あなたはOKボタンの完了ハンドラ内に行きたいのViewController Instatise

答えて

0

これは私が使用している例です。私がどこからでも呼び出すことができるそのクラス関数は、私は難しいコードを持っています。これは、ナビゲーションコントローラの一部であるView Controllerをコーディングしました。単に "LogInNavCont"をviewcontrollerのストーリーボードIDに変更し、UINavigationControllerをUIViewControllerに変更します。独立したviewController。あなたはクラスの関数としてそれを使用したくない場合は、ちょうどself.presentするclassName.presentを交換

class func createAlertAndGoToLogin(errorTitle: String, errorMessage: String, className: UIViewController) { 
    let alert = UIAlertController(title: errorTitle, message: errorMessage, preferredStyle: UIAlertControllerStyle.alert) 
    alert.addAction(UIAlertAction(title: "Ok", style: .default, handler: { (action) in 

     // go back to the login view controller 
     // go back through the navigation controller 

      let vc = className.storyboard!.instantiateViewController(withIdentifier: "LogInNavCont") as! UINavigationController 
      className.present(vc, animated: false, completion: nil) 


    })) 
    className.present(alert, animated: true, completion: nil) 
} 
関連する問題