0

ViewControllerアラートビューで「次へ」ボタンを押すと、配列を別の配列に渡したいと思います。

userInformation += [userName, userGender, String(userAge), String(userHeight), String(userWeight)]

let alert = UIAlertController(title:"Confirmation", message: confirmationMessage, preferredStyle: UIAlertControllerStyle.Alert)

let confirmBtn : UIAlertAction = UIAlertAction(title: "Next", style: UIAlertActionStyle.Default, handler: {(action:UIAlertAction!)-> Void in

    let vc = (self.storyboard?.instantiateViewControllerWithIdentifier("toPerInfo"))! as UIViewController

    print(self.userInformation)

    self.showDetailViewController(vc, sender: self)

})

let cancelBtn : UIAlertAction = UIAlertAction(title: "Cancel", style: UIAlertActionStyle.Cancel, handler: nil)

    alert.addAction(cancelBtn)
    alert.addAction(confirmBtn)

    self.presentViewController(alert, animated: true, completion: nil)

そしてここにperpareForSegue

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
        var destViewController: PersonalInformation = segue.destinationViewController as! PersonalInformation
        var arrayToSegue: [String] = self.userInformation
        destViewController.useInfo = arrayToSegue
    }

perpareForSegue「次へ」ボタンに入れたいと思います。コードをどのように変更すればよいですか..他の同様の質問が見つかりませんでした...

4

1 に答える 1

0

このメソッドは、ドキュメントprepareForSegueに書かれているように、実際には新しいView Controllerをカスタマイズまたはデータを渡すために作成されています。UIViewController

このメソッドのデフォルトの実装は何もしません。サブクラスはこのメソッドをオーバーライドし、それを使用して新しいView Controllerを表示する前に構成します。セグエ オブジェクトには、関係する両方のビュー コントローラーへの参照を含む、遷移に関する情報が含まれています。


本当にしたい場合は、PersonalInformationView Controllerを手動でプッシュできます。

let storyboard = UIStoryboard(name: "StoryboardName", bundle: nil)
let destVC = storyboard.instantiateViewControllerWithIdentifier("PersonalInformationId") as! PersonalInformation
var arrayToSegue: [String] = self.userInformation
destVC = arrayToSegue

// present or push, as you wish 
presentViewController(destVC, animated: true, completion: nil)
于 2016-02-25T07:33:50.363 に答える