title: How to create a action to a button in Cocoa programmatically?
body: <p>I'm trying to create a button in Cocoa in mac programmatically, but I don't know how to put a action on this, I'm trying like this:</p>
  
  <pre><code>NSRect frame = NSMakeRect(10, 200, 80, 100);
  NSButton *btn = [[NSButton alloc]initWithFrame:frame];
  [btn setButtonType:NSMomentaryPushInButton];
  [btn setBezelStyle:NSRoundedBezelStyle];
  [btn setTitle:@"Click me"];
  [btn setAction:@selector(hideLabels:)];
  
  [view addSubview:btn];
  </code></pre>
  
  <p>but the line [btn setAction:@selector(hideLabels:)]; don't work, how can I create a action here?</p>
  
  <p>the method hideLabels is in function, because I used it with another button.</p>