Say I have a button that, when tapped, should perform two actions:
func firstFunction() {
...
}
func secondFunction() {
...
}
I know that I can connect an object to one action. Though it doesn't seem like I can connect it to more than one. I tried dragging and dropping the plus circle (please see image) but it doesn't seem to connect to the secondFunction()
.
Functions shouldn't have side effects. Say, for instance, that I want to call firstFunction
from somewhere in my code, but not secondFunction
.
Can I connect an object to more IBAction
s in iOS?
Yes. In iOS, most (all?) objects that use the target/action paradigm support multiple targets and actions. Just control-drag from the sender (or a specific sent event of the sender) to each action, one at a time: