Segue and Button programmatically fast

I am using iCarousel and I need to create my own button. I want to transfer data from a button made programmatically to another view, but I don't have a segue identifier because I created the button programmatically. I do not know if it is possible to programmatically create a segue identifier.

button.addTarget(self, action: #selector(buttonAction3), for: .touchUpInside) button.setTitle("\(titulos[index])", for: .normal) tempView.addSubview(button) let myImage = UIImage(named: "modo4.png") as UIImage? button.setImage(myImage, for: .normal) let viewController:UIViewController = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "modo") as! Modo1ViewController self.present(viewController, animated: false, completion: nil) if segue.identifier == "" { if let destination = segue.destination as? Modo1ViewController { destination.nomb = nombres } } 
+7
button swift programmatically-created segue
source share
2 answers

Create sowing.

Create Seuge

assign an identifier

enter image description here

and the purpose of your button

  @IBAction func button_clicked(_ sender: UIButton) { self.performSegue(withIdentifier: "segueToNext", sender: self) } override func prepare(for segue: UIStoryboardSegue, sender: Any?) { if segue.identifier == "segueToNext" { if let destination = segue.destination as? Modo1ViewController { destination.nomb = nombres // you can pass value to destination view controller } } } 
+11
source share

in your case, if you use self.present and you want to send data between the presentations. Try the following:

 let viewController:UIViewController = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "modo") as! Modo1ViewController viewController.nomb = nombres self.present(viewController, animated: false, completion: nil) 

I don't know how to set the segue id, but I think the code above might help

If you want to make the job easier, you can create a segue in IB (Interface Builder) and set its identifier, and then use

 performSegue:withIdentifier:sender 
0
source share

All Articles