私はで立ち往生していUIAlertController
ます。
私はこのアラートビューを持っています:
@IBAction func AddPatientButton(sender: AnyObject) {
let alert = UIAlertController(title:"Registro Paciente", message: "Paciente Registrado", preferredStyle: UIAlertControllerStyle.Alert)
alert.addAction(UIAlertAction(title:"Ok", style: UIAlertActionStyle.Default, handler: nil))
self.presentViewController(alert, animated: true, completion: nil)
}
そして、それは私にアラートビューを正しく表示します。しかし、私が欲しいのは、ユーザーが[OK]ボタンを押すと、このボタンがセグエを実行し、ユーザーを別のViewControllerに送信することです。
このサンプルコードはあなたが望むことをします。
@IBAction func AddPatientButton(sender: AnyObject) {
let alert = UIAlertController(title:"Registro Paciente", message: "Paciente Registrado", preferredStyle: UIAlertControllerStyle.Alert)
alert.addAction(UIAlertAction(title:"Ok", style: UIAlertActionStyle.Default, handler: { alertAction in
// Code to segue/change VC !
self.performSegueWithIdentifier("segue_name", animated: true)
//
}))
移動先のViewControllerにセグエを作成し、そのセグエにインスペクターでIDを指定してください(セグエをクリックしてインスペクターを確認してください)。次に、その識別子を「segue_name」がある場所にコピーして貼り付けます。
画像で表示させてください:
1)新しいVCを追加します(明らかに行きたいVCがすでにある場合を除く)。次に、Ctrlキーを押しながら、元のVCの黄色のアイコンから移動先のVCにドラッグします。
2)[表示]または探しているオプションを選択します。
3)セグエ(表示された矢印)を選択し、属性インスペクター(右上)をクリックして、識別子を入力します。
次に、私が提供したコードの「segue_name」にある識別子をコピーして貼り付けます。
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加