Ios 试图通过UIAlert以编程方式移动
当你按下ok时,我正试图通过一个提示弹出窗口从一个视图切换到另一个视图 问题是我尝试使用的代码没有从一个屏幕移动到另一个屏幕。我不知道为什么 守则:Ios 试图通过UIAlert以编程方式移动,ios,swift,uialertcontroller,Ios,Swift,Uialertcontroller,当你按下ok时,我正试图通过一个提示弹出窗口从一个视图切换到另一个视图 问题是我尝试使用的代码没有从一个屏幕移动到另一个屏幕。我不知道为什么 守则: import UIKit class ViewController: UIViewController { @IBAction func helpButtonPushed(_ sender: UIButton) { let alertController = UIAlertController(title: "Help h
import UIKit
class ViewController: UIViewController {
@IBAction func helpButtonPushed(_ sender: UIButton) {
let alertController = UIAlertController(title: "Help has been sent", message: "Please move towards the Student Services Area. ", preferredStyle: .alert)
self.present(alertController, animated: true, completion: nil)
let okAction = UIAlertAction(title: "Ok", style: .default, handler: { (alertAction) in
//Show the quiz.
let storyBoard : UIStoryboard = UIStoryboard(name: "QuizViewcontroller", bundle:nil)
let nextViewController = storyBoard.instantiateViewController(withIdentifier: "Quiz") as! QuizViewController
self.present(nextViewController, animated:true, completion:nil)
})
alertController.addAction(okAction)
}
}
我尝试使用的两个ViewController:ViewController和QuizViewController
提前感谢检查视图控制器是否在未使用警报的情况下显示。如果工作正常:首先显示您的警报。我没有看到首先显示警报的代码。 以下代码可以正常工作: @已按下iAction func HelpButton(\发送方:UIButton){ 让alert=UIAlertController(标题:“你好”,消息:“你好”,首选样式:。alert)
对于
UIStoryBoard
PutQuizViewcontroller
不是很好的命名约定,请使用Main
,这是默认设置,或者您可以使用项目的部署信息检查它-
定义“不起作用”。在没有明确说明实际发生了什么和应该发生什么的情况下,不要使用这些词。您是否收到任何错误消息?您的问题是否包括有关您的问题的所有相关细节。QuizViewController可能不是QuizViewController?
let okAction = UIAlertAction(title: "Ok", style: .default, handler: { (alertAction) in
let storyBoard : UIStoryboard = UIStoryboard(name: "Main", bundle:nil)
let nextViewController = storyBoard.instantiateViewController(withIdentifier: "ViewController2")
self.present(nextViewController, animated:true, completion:nil)
})
alert.addAction(okAction)
self.present(alert, animated: true, completion: nil)
}
let storyBoard : UIStoryboard = UIStoryboard(name: "Main", bundle:nil)