How to pass values from a Pop Up View Controller to the Previous View Controller?

前端 未结 3 2124
星月不相逢
星月不相逢 2021-01-26 06:04

So In my 1stViewController I have this code:

@IBAction func colorDropdown(_ sender: Any) {
    self.popUpColorPicker()
}

func popUpColorPicker() {
    let popOv         


        
3条回答
  •  我在风中等你
    2021-01-26 06:18

    you can always use unwind to do some stuff upon unwinding

    declare a IBAction in your first vc

    var color: UIColor!
    @IBAction func unwindToCheckout(segue: UIStoryboardSegue) { 
       //do some stuff with color
    }
    

    then create exit segue for popout viewcontroller then you can dismiss popout like this

    self.performSegueWithIdentifier("unwindToVC1", sender: selectedColor)
    

    then in prepareForSegue

    if segue.identifier == "unwindToVC1" {
      (segue.destinationViewController as! FirstViewController).color = sender as! UIColor
    }
    

    also you can create delegate to reach fistviewcontroller and do some stuff which is way easier to do

提交回复
热议问题