我正在开发一个简单的测验应用。
我有一个带有 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/