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实际上是为了自定义或将数据传递给新的视图控制器,如UIViewController 文档中所述:

此方法的默认实现什么也不做。子类覆盖此方法并在显示之前使用它来配置新的视图控制器。segue 对象包含有关转换的信息,包括对所涉及的两个视图控制器的引用。


如果你真的想,你可以手动推送PersonalInformation视图控制器:

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 回答