How to access button data?

Am using Xode 10.0 for a ios app and need to access the button title for it's current state, analyze and/or change it.


Am using IBAction func "button name" (_sender:AnyObject) { code }


I have tried UITextview's "name" .text = title but does show up in the textview.


When trying to print the contents of title it yields nil although there is data in the button title and appears on the button view.


Am using the simulator for iphone xr and when using "name" .text = "AB" it will show in textview on simulator button press.




Thanks...Charlie

Replies

You have to define an IBOutlet for the buton:


control-drag from the button to the beginning of the ViewController class code, give a name as myButton


You will get a declaration generated in code as:

@IBOutlet var myButton : UIButton!


You can now access properties.

myButton.title = "new title"

Did you solve your problem ?