Теоретически:
Если вы переходите к следующему ViewController
из current , вы можете создать переменную внутри следующего View Controller и при переходе от текущего VC к следующему вы можете извлечь имя Button внутри метода @IBAction
, создать экземпляр следующего VC и получить доступ к этой переменной (созданныйранее) и назначьте имя этой кнопки этой переменной
код:
class CurrentViewController: UIViewController {
// Your other code goes here
@IBAction func actionButtonTapped(_ sender: UIButton) {
// Here we fetch the name of the button tapped
let nameOfButtonTapped = sender.titleLabel!.text
// Here we create instance of NextViewController
let nextVC = self.storyboard?.instantiateViewController(withIdentifier: "#yourNextVCIdentifierHere") as! NextViewController
// Here we assign the name of the button tapped to the variable of NextViewController so we can access it there
nextVC.buttonNameThatWasClicked = nameOfButtonTapped
self.present(nextVC, animated: true, completion: nil)
}
}
class NextViewController: UIViewController {
var buttonNameThatWasClicked: String?
override func viewDidLoad() {
super.viewDidLoad()
print(buttonNameThatWasClicked!)
}
}
Здесь мы можем подключить ВсеКнопки к одному @IBAction
, перетаскивая все кнопки на имя метода @IBAction