1
我希望按鈕去QaController,如果單詞你好輸入,否則我想警報出現,然後回到主屏幕(viewController),但它似乎並沒有工作UIButton if swift
@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語句,所以我不知道什麼是錯:/
什麼不順心的是當我點擊提交後,當我在它把「你好」顯示黑屏,無錯誤消息,而不是顯示正確的視圖
在此先感謝!
'但它似乎並不工作'這是什麼意思:是否有錯誤消息,如果是的哪一個?預期會發生什麼,發生了什麼?請始終提供背景和細節。謝謝! :) – Moritz
你在使用故事板嗎?如果是這樣,你需要從故事板實例化,而不是:storyBoard.instantiateViewControllerWithIdentifier(CONTROLLERIDENTIFIERINSTORYBOARDASSTRING)。您可能正在創建一個沒有UI的控制器。 – Orion
首先使用打印檢查您的文本字段是否包含內容。 –