我想在按下警报视图中的"Next“按钮时将一个数组传递给另一个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放入“下一步”按钮。我应该如何修改我的代码..我找不到其他类似的问题...
发布于 2016-02-25 15:33:50
正如在UIViewController documentation中所写的,prepareForSegue方法实际上是用来定制数据或将数据传递给新的视图控制器的:
此方法的默认实现不执行任何操作。子类覆盖此方法,并在显示新的视图控制器之前使用它配置新的视图控制器。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)https://stackoverflow.com/questions/35620663
复制相似问题