Segue和Button以編程方式迅捷我正在使用iCarousel,我必須創(chuàng)建自己的按鈕。我想將編程按鈕中的數(shù)據(jù)傳遞給另一個視圖,但我沒有segue標(biāo)識符,因為我以編程方式創(chuàng)建了按鈕。我不知道是否可以通過編程方式創(chuàng)建segue的標(biāo)識符。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! Modo1ViewControllerself.present(viewController, animated: false, completion: nil)if segue.identifier == "" {
if let destination = segue.destination as? Modo1ViewController {
destination.nomb = nombres }
}
2 回答

一只萌萌小番薯
TA貢獻1795條經(jīng)驗 獲得超7個贊
創(chuàng)造seuge
分配標(biāo)識符
和你的按鈕目標(biāo)
@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 } } }

不負(fù)相思意
TA貢獻1777條經(jīng)驗 獲得超10個贊
在您的情況下,如果您使用self.present并且您想要在視圖之間發(fā)送數(shù)據(jù)。試試這個:
let viewController:UIViewController = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "modo") as! Modo1ViewControllerviewController.nomb = nombresself.present(viewController, animated: false, completion: nil)
我不知道如何設(shè)置segue的標(biāo)識符,但我認(rèn)為上面的代碼可以提供幫助
如果您想更輕松地工作,可以在IB(Interface Builder)中創(chuàng)建segue并設(shè)置它的標(biāo)識符,然后使用
performSegue:withIdentifier:sender
- 2 回答
- 0 關(guān)注
- 497 瀏覽
添加回答
舉報
0/150
提交
取消