我在 View Controller 之间传递数据,并试图将一个特定的 int 从一个 View Controller 发送到另一个 View Controller 。
现在,我的代码如下所示:
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
let werrk = segue.destination as! ViewControllerTwo
werrk.dataSent = (sender as! UIButton).title(for: .normal)!
}
它成功地将按钮的标题发送到新的 View Controller 。为了也识别一个特定的按钮并发送一个 int,我想象添加一些 if/else 语句,比如......
if sender = button1 {
work.dataSent = 7
}
但是我找不到正确的命令来实现这一点。 我对这一切都不熟悉,任何帮助将不胜感激。非常感谢!
最佳答案
尝试在每个按钮上添加一个标签,然后用它来识别 if/switch
Button1.tag = 1
然后在你的事件触发器上做类似的事情
if (sender.tag == 1) {
// do stuffs
}
关于ios - 如何将特定按钮识别为发件人,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42941230/