ios - 即使我在 Storyboard 中设置了 segue,prepareForSegue 也从未被调用

标签 ios swift uiviewcontroller segue

我是 iOS 开发的新手,我正在尝试学习 Udacity 中的类(class)。

但是在执行 segue 时遇到了问题。

prepareForSegue 从未在我的第二个 View Controller 中被调用。

我有两个 View Controller ,一个是ViewController,另一个是PlaySoundViewController

enter image description here

并且我已将 Storyboard中的内容链接到 swift 中的真实类(class)。

enter image description here


enter image description here


enter image description here

我已经从第一个 View Controller 拖到第二个 View Controller 以生成一个 segue 并将其命名为“gonext”。

enter image description here

我调用了 performSegueWithIdentifier("gonext", sender:aduio);

在第二个 View Controller 中,我实现了 prepareForSegue,但是,它从未被调用....但它设法转到下一个 View 。 enter image description here

最佳答案

要转到下一个 View Controller ,您必须执行该方法

Self.performSegueWithIdentifier("gonext", sender:aduio);

你弄错的一件事是你必须在第一个 View Controller 而不是第二个 View Controller 中运行 prepareForSegue 方法来发送数据。

因此,与其在第二个 View Controller 中运行 prepareForSegue 方法,不如在第一个 View Controller 中运行它。

关于ios - 即使我在 Storyboard 中设置了 segue,prepareForSegue 也从未被调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31822954/

相关文章:

ios - 在 Swift 中使用命名 Assets 初始化 URL() 的正确方法?

ios - TableView didSelect row 问题

ios - 如何以编程方式为 iPhone SE 和 iPhone 5S 编写自动布局?

ios - 如何从一个 UIView 更改另一个 UIView 上的标签

ios - 自动布局 UITextField 以适应 UINavigationBar

ios - 将 native html react 为 pdf

ios - 以编程方式执行多个 segue

ios - 使用可变参数格式化字符串

ios - 来自另一个 View Controller 时的 xcode 问题

xcode - iOS (Swift) - View Controller 上的选项卡式导航