How do I retrieve the value of a button?
For example:
I have a button in my layout with the name Test button , but I want to assign the name of this button to be clicked on a variable!
Is this possible?
Thank you ] 1
How do I retrieve the value of a button?
For example:
I have a button in my layout with the name Test button , but I want to assign the name of this button to be clicked on a variable!
Is this possible?
Thank you ] 1
Just get the sender.titleLabel.text
, as it is a UIButton
, there is no property value
Since your sender is AnyObject
, you'll need to cast it
let value = sender.titleLabel.text as! String
If you use this button-only method, I recommend moving from AnyObject
to UIButton
Edit
You need to get the label of the button ( titleLabel
) and then get the text ( text
) as above example
To do this, you need to check the sender.tag
property and use its name to identify which button is being triggered.