我的FirstViewController
中有多个按钮,每个按钮被单击时,都会带我到SecondViewController
。在SecondViewController
中有一个textfield
,应根据所单击的按钮为textfield.text
分配一个特定值。
是否可以检测到按下了哪个按钮?
最佳答案
如果您这样声明操作,则按钮将自身作为操作的sender
参数传递:
@IBAction func buttonWasTapped(_ sender: Any) {
guard let button = sender as? UIButton else { return }
// use button…
}