Xcode Swift 使用警报执行 segue

Posted

技术标签:

【中文标题】Xcode Swift 使用警报执行 segue【英文标题】:Xcode Swift perform segue with alert 【发布时间】:2017-09-30 11:25:59 【问题描述】:

我有三个 ViewController。当您单击出现警报的Ok 按钮时,我想执行从ThirdViewControllerSecondViewController 的转换。我已经尝试过使用此代码:

alert.addAction(UIAlertAction(title: "Ok!", style: UIAlertActionStyle.default, handler:  action -> Void in
     self.performSegue(withIdentifier: "ThirdViewControllerSegueBack", sender: self)
))

问题是SecondViewController 的新窗口出现了,所以当我点击导航栏上的back 时,它会将我带回到ThirdViewController。我希望它显示FirstViewController

【问题讨论】:

你需要一个放松的转场:***.com/questions/12561735/… 如果它适用于你的场景,试试这个:***.com/questions/45792130/… 看看这个方法:(展开segues)medium.com/@mimicatcodes/… 【参考方案1】:

在 SecondViewController 中,您必须创建 Unwind segue

@IBAction func unwindToController2(segue:UIStoryboardSegue)   

ViewController3 中的情节提要从 ViewController 拖动到退出 Button 并添加 segue。为其添加标识符,并调用 UIAlertController

【讨论】:

@lolinger2001 不客气)请检查答案是否正确)

以上是关于Xcode Swift 使用警报执行 segue的主要内容,如果未能解决你的问题,请参考以下文章