Call function from other ViewController

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

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

4条回答
  •  不要未来只要你来
    2021-01-24 16:04

    If you want to show alert view to second viewcontroller from firstview controller when go to it you can do something like,

      self.performSegueWithIdentifier("your segue identifier", sender: self)  // or whatever way if you are not using storyboard or segue
    
        let alert = UIAlertView(title: "Working!", message: "This function was called from FirstViewController!", delegate: nil, cancelButtonTitle: "Okay")
        alert.show()
    

    If you want to set any variables of secondviewcontroller then you need to implement prepareForSegue method. (if you are using segue).

    Second thing you can show alertview in viewDidload of secondViewController also.

提交回复
热议问题