Segue 和 Button 以编程方式快速

编程入门 行业动态 更新时间:2024-10-28 12:19:10
本文介绍了Segue 和 Button 以编程方式快速的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在使用 iCarousel,我必须创建自己的按钮.我想将数据从以编程方式制作的按钮传递到另一个视图,但我没有 segue 标识符,因为我以编程方式创建了按钮.我不知道是否可以以编程方式创建 segue 的标识符.

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

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 } }

推荐答案

创建 seuge

分配标识符

和你的按钮目标

@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 // destination.nomb = arrayNombers[(sender as! UIButton).tag] // Using button Tag } } }

更多推荐

Segue 和 Button 以编程方式快速

本文发布于:2023-11-06 09:32:31,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1563320.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:快速   方式   Segue   Button

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!