【发布时间】:2023-03-08 18:59:01
【问题描述】:
如果键入 Hello 一词,我希望按钮转到 QaController,否则我希望出现警报,然后返回主屏幕 (viewController),但它似乎不起作用
@IBAction func submitButton(sender: AnyObject) {
if TextField.text.containsString("Hello"){
let secondViewController:QaController = QaController()
self.presentViewController(secondViewController, animated: true, completion: nil)
} else {
let alertController = UIAlertController(title: "Thank You!", message:
"We appreciate your feedback!", preferredStyle: UIAlertControllerStyle.Alert)
alertController.addAction(UIAlertAction(title: "Dismiss", style: UIAlertActionStyle.Default,handler: nil))
self.presentViewController(alertController, animated: true, completion: nil)
let homeViewController:ViewController = ViewController()
self.presentViewController(homeViewController, animated: true, completion: nil)
}
}
代码在没有 IF 语句的情况下可以正常工作,所以我不确定出了什么问题:/
问题是当我点击提交时,当我输入“你好”时,它显示一个没有错误消息的黑屏,而不是显示正确的视图
提前致谢!
【问题讨论】:
-
but it doesn't seem to work这是什么意思:是否有错误消息,如果是,是哪一个?预期会发生什么,反而发生了什么?请始终提供上下文和详细信息。谢谢! :) -
您在使用情节提要吗?如果是这样,您需要从情节提要中实例化:storyBoard.instantiateViewControllerWithIdentifier(CONTROLLERIDENTIFIERINSTORYBOARDASSTRING)。您可能正在创建一个没有 UI 的控制器。
-
首先检查您的文本字段是否有内容,使用打印。