首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在UIAlertAction中添加prepareForSegue

在UIAlertAction中添加prepareForSegue
EN

Stack Overflow用户
提问于 2016-02-25 15:12:42
回答 1查看 169关注 0票数 0

我想在按下警报视图中的"Next“按钮时将一个数组传递给另一个ViewController

代码语言:javascript
复制
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

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

我想将perpareForSegue放入“下一步”按钮。我应该如何修改我的代码..我找不到其他类似的问题...

EN

回答 1

Stack Overflow用户

发布于 2016-02-25 15:33:50

正如在UIViewController documentation中所写的,prepareForSegue方法实际上是用来定制数据或将数据传递给新的视图控制器的:

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

如果您确实需要,可以手动推送PersonalInformation视图控制器:

代码语言:javascript
复制
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)
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/35620663

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档