How to simulate a button click in swift (for MAC OSX)
I'm making a program for Mac and I need to find a way to" click " a button from a code.
I'm trying to put this code on another button and have already tried this in the following 3 Ways:
func mouseDown(_ NSButton1: NSEvent) { }
func performClick(_ NSButton1: NSEvent) { }
Button1.sendActionsForControlEvents(NSControlEvents.TouchUpInside)
Does anyone know how to do this?
2
1 answers
Hello! If you want to define what will happen to a button after you click it, just make connect the Storyboard button to the code, choose the type of connection as Action. Thus, a new function will be created, for example:
@IBAction func sampleFunction(sender: AnyObject) {
}
Now, inside the brackets, write the actions you want. For example:
@IBAction func sampleFunction(sender: AnyObject) {
print("Você clicou em mim!!")
}
In this case, every time you click the button, the string " you clicked on me!"will be" printed " in XCode.
0
Author: Mila, 2016-09-22 17:44:54