Swift: prepareForSegue with two different segues

后端 未结 5 909
旧时难觅i
旧时难觅i 2021-01-04 19:29

I have 2 UIButtons on a view. Each of them are linked to 2 different views. They have to pass different data depending which button you just tapped.

I k

5条回答
  •  离开以前
    2021-01-04 19:33

    prepareForSegue with two different segues when you click on button uialert controller will show it will give you three options 1. physical, 2. online and 3. cancel.

    @objc func twoSegues(sender : UIButton) {
    let alert = UIAlertController(title: "Update Request", message: "Are you sure to update the record!", preferredStyle: .alert)
            let yes = UIAlertAction(title: "Yes", style: .default, handler: { [weak self] (UIAlertAction) in
    
                if(serviceType == "physical") {
                    DispatchQueue.main.async {
                        self?.performSegue(withIdentifier: "physical", sender: self?.myArray[id!].serviceID)
    
    
                     }
                }
                 if(serviceType == "online") {
                    DispatchQueue.main.async {
                        self?.performSegue(withIdentifier: "online", sender: self?.myArray[id!].serviceID)
                     }
                }
            })
            let no = UIAlertAction(title: "No", style: .default, handler: nil)
            alert.addAction(yes)
            alert.addAction(no)
    
            self.present(alert, animated: true, completion: nil)
        }
    }
    

提交回复
热议问题