5

I am iOS developer and I want to develop a Mac app (it's basically a "port" from an iOS app). In IB in iOS is very easy to connect one UIButton to two or more actions. I have noticed that in a Mac App I only can connect a NSButton to a single action. Is there a way to connect an NSButton to more than one action?

Anoop Vaidya
  • 46,283
  • 15
  • 111
  • 140
  • 2
    Why not just have the button call a common handler that calls two methods? Seems simpler than having multiple targets for a singular action. – CodaFi May 29 '13 at 05:10
  • you can call multiple methods inside the action like [self method] . – NewStack May 29 '13 at 05:11
  • First of all, in ios you have less view area so you use one button with multiple actions. in osx you have a big screen area, you can create multiple buttons..isn't it – Anoop Vaidya May 29 '13 at 05:11
  • 1
    @AnoopVaidya I suspect that the real reason is because AppKit controls store targets and selectors based on the control event rather than on the selector-target pair. – CodaFi May 29 '13 at 05:18
  • @CodaFi: yes I agree. – Anoop Vaidya May 29 '13 at 05:43

1 Answers1

4

Is there a way to connect an NSButton to more than one action?

NO. This is not supported in OSX Cocoa applications.

You need to setAction: yourself based on conditions, But only one at a time can be used.

In case you want to call two methods(actions), in the IBAction method you need to call them.

-(IBAction)multipleActions:(id)sender{
    [self method1:sender];
    [self method2:sender];
}
Anoop Vaidya
  • 46,283
  • 15
  • 111
  • 140