show UIAlertController outside of ViewController

前端 未结 4 2133
隐瞒了意图╮
隐瞒了意图╮ 2021-02-01 07:43

I have trouble to display my UIAlertController because I\'m trying to show it in a Class which is not an ViewController.

I already tried adding it:

 var          


        
4条回答
  •  梦如初夏
    2021-02-01 08:36

    Create a helper function that you call from the current view controller and pass the current view controller as a parameter:

    func showAlertInVC(
      viewController: UIViewController, 
      title: String, 
    message: String)
    {
      //Code to create an alert controller and display it in viewController
    }
    

提交回复
热议问题