0
當按下alertview中的「Next」按鈕時,我想將數組傳遞給另一個ViewController
。將prepareForSegue添加到UIAlertAction中
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
進入 「下一步」 按鈕。 我應該如何修改我的代碼.. 我無法找到其他類似的問題...
或者是有什麼辦法可以傳遞數據,而不SEGUE? – chiefpika
您可以使用手動推送或像我的示例一樣呈現。但是你必須手動使用它(調用push或者present方法),或者使用segue。 –