Call function from other ViewController

前端 未结 4 1676
深忆病人
深忆病人 2021-01-24 15:31

I have two ViewControllers, FirstViewController and SecondViewController. Both have an own Swift file, FirstViewController.swift and

4条回答
  •  闹比i
    闹比i (楼主)
    2021-01-24 15:57

    Try this:

    SecondViewController().showAlert(self)
    

    In your second view controller

     if let text = textField?.text {
         dispatch_async(dispatch_get_main_queue(),{
    
          let alert = UIAlertView(title: "Working!", message: "This function was called from FirstViewController!\nTextField says: \(text)", delegate: nil, cancelButtonTitle: "Okay")
          alert.show()
    
        })
    }
    

提交回复
热议问题