ios - 如果条件为真,如何转移到特定的 Storyboard?

标签 ios swift uiviewcontroller segue uistoryboardsegue

我正在开发一个简单的测验应用。

我有一个带有 TextView (包含一个问题)和 3 个按钮(答案)的 Storyboard 当用户按下答案时,我需要检查答案是否正确。如果正确,将出现另一个 Storyboard(包含成功消息)。 所以我为每个按钮做了一个 Action ,但问题是第二个 Storyboard(成功消息)只出现了几秒钟,然后预览 Storyboard(问题)再次出现..我希望成功的消息出现在屏幕上 这是代码:

  @IBAction func click1(_ sender: Any) {
    if (opt1.titleLabel?.text) != nil {
        let userAnswer=opt1.titleLabel?.text;

        if ((userAnswer!.elementsEqual(self.optionsArray[0])) == true)
        {
           playSound(fileName: "kidsCheering")

            let storyBoard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
            let QMessagesViewController = storyBoard.instantiateViewController(withIdentifier: "QMessage") as! QMessagesViewController
            self.present(QMessagesViewController, animated: true, completion: nil)
        }

谢谢

这是我得到的错误:在演示过程中尝试演示!

最佳答案

请像这样更改您的 viewcontroller 变量名称,如果添加或仅使用 segue,请删除 segue:

    let qMessagesVC = storyBoard.instantiateViewController(withIdentifier: "QMessage") as! QMessagesViewController
    self.present(qMessagesVC, animated: true, completion: nil)

关于ios - 如果条件为真,如何转移到特定的 Storyboard?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54401341/

相关文章:

iphone - 如何使 View 看起来像报摊书架

ios - StoryBoard 中的自定义 Table ViewController

iphone-sdk-3.0 - 当我的UIViewController从IBAction访问AppDelegate中的NSArray时,程序崩溃

ios - 如何使用沙盒帐户在iOS 12中测试应用内购买?

ios - NSNumberformatter 添加额外的零

arrays - 索引超出范围 - Swift

swift - 如何检测自上次在 macOS 中输入 NSTextView 后用户不活动?

iphone - 在父 View Controller 和 subview Controller 之间进行通信的更好方法是什么?

ios - 如何在 Swift 中合并多个数组?

具有深度链接的 iOS 9 搜索功能