首页 > 解决方案 > 在 UIViewContriller Swift 5 中的 func viewDidLoad() 之后运行 UIAlertController

问题描述

我需要在加载视图后立即显示警报。此代码被忽略。如何获得此警报?

class TrailerViewController: UIViewController {

  override func viewDidLoad() {
    super.viewDidLoad()
    if gConnected == false{
      let alert = UIAlertController(title: "Wifi Not Connected", message: "The Wifi is not connected to the Trailer Expert.", preferredStyle: .alert)

      alert.addAction(UIAlertAction(title: "Connect", style: .default, handler: connectWifi()))
      alert.addAction(UIAlertAction(title: "Ignore", style: .cancel, handler: nil))

      self.present(alert, animated: true)
    }
    // Do any additional setup after loading the view, typically from a nib.
  }

标签: iosswiftuiviewcontrolleruialertcontroller

解决方案


推荐阅读