• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: NSToolbarItem Action Not Passed to NSButton...
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSToolbarItem Action Not Passed to NSButton...


  • Subject: Re: NSToolbarItem Action Not Passed to NSButton...
  • From: Andy Lee <email@hidden>
  • Date: Fri, 25 Apr 2014 02:17:00 -0400

Okay, I just brushed up a bit on toolbars (wow, it's been a *very* long time).

How did you create the instance of RBSStopButtonToolbarItem in the nib?  From the docs, I learned that you can drag a view (in your case a button) from the IB palette into the Allowed Toolbar Items area.  This should create exactly what you wanted: a view-based toolbar item containing an NSButton.  Then you could:

* Set the class of the toolbar item to your custom class.
* Set the button's image, alt image, and target in IB.

See <https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/Toolbars/Articles/ToolbarInIB.html#//apple_ref/doc/uid/TP40008136-SW3>.

Also, aren't you getting lots of NSLog messages from your validate method?  Validation occurs with every mouse click and keypress, which means you're assigning a brand new NSButton to _button over and over and over.

The stuff you're doing in validate would typically be done in awakeFromNib.  Check the documentation for awakeFromNib; it explains a lot about nib loading.  BUT it seems to me you don't need any code to create the button.  You can do it in IB.

What *should* go in the validate method is logic to enable or disable the button as appropriate at any given time.  So you'll still want RBSStopButtonToolbarItem to have a button property, but you'll want to:

* Add IBOutlet to the property declaration.
* In IB, connect the toolbar item to the button.
* Implement -[RBSStopButtonToolbarItem validate] to enable the button if a "Stop" operation makes sense, otherwise disable it.

--Andy

On Apr 25, 2014, at 1:23 AM, "Peters, Brandon" <email@hidden> wrote:

> I tried and nothing. The IBOutlet is on the NSToolbarItem custom class. Here is my custom class:
>
> @interface RBSStopButtonToolbarItem : NSToolbarItem
> {
>     NSButton *_button;
> }
>
> @property (readwrite) NSButton *button;
>
> @end
>
> @implementation RBSStopButtonToolbarItem
>
> @synthesize button = _button;
>
> -(id)initWithItemIdentifier:(NSString *)itemIdentifier
> {
>     self = [super initWithItemIdentifier:itemIdentifier];
>
>     if(self)
>     {
>         // set min and max size
>         [self setMinSize:NSMakeSize(32.0, 32.0)];
>         [self setMaxSize:NSMakeSize(32.0, 32.0)];
>
>         NSLog(@"Self: %@", self);
>
>     }
>     return self;
> }
>
> -(void)validate
> {
>     NSLog(@"Validate called...");
>     // set the original and alternate images...names are "opposite"
>
>     _button = [[NSButton alloc] initWithFrame:NSMakeRect(0, 0, 32, 32)];
>
>     //[_button setFrameSize:NSMakeSize(32.0, 32.0)];
>
>     NSImage *image = [NSImage imageNamed:@"StopButtonAlternateIcon"];
>     [image setSize:NSMakeSize(32.0, 32.0)];
>     [_button setImage:image];
>
>     image = [NSImage imageNamed:@"StopButtonIcon"];
>     [image setSize:NSMakeSize(32.0, 32.0)];
>     [_button setAlternateImage:image];
>
>     // image position
>     [_button setImagePosition:NSImageOnly];
>
>     // set button type
>     [_button setButtonType:NSToggleButton];
>
>     // button is transparent
>     [_button setBordered:NO];
>
>     // set the toolbar item view to the button
>     [self setView:_button];
> }
>
> @end
>
> The images will display, but the action does not seem to “connect”, even though it is done in IB.


_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden


  • Follow-Ups:
    • Re: NSToolbarItem Action Not Passed to NSButton...
      • From: "Peters, Brandon" <email@hidden>
References: 
 >NSToolbarItem Action Not Passed to NSButton... (From: "Peters, Brandon" <email@hidden>)
 >Re: NSToolbarItem Action Not Passed to NSButton... (From: Andy Lee <email@hidden>)
 >Re: NSToolbarItem Action Not Passed to NSButton... (From: "Peters, Brandon" <email@hidden>)
 >Re: NSToolbarItem Action Not Passed to NSButton... (From: Andy Lee <email@hidden>)
 >Re: NSToolbarItem Action Not Passed to NSButton... (From: "Peters, Brandon" <email@hidden>)
 >Re: NSToolbarItem Action Not Passed to NSButton... (From: Andy Lee <email@hidden>)
 >Re: NSToolbarItem Action Not Passed to NSButton... (From: "Peters, Brandon" <email@hidden>)

  • Prev by Date: Re: GCD killed my performance
  • Next by Date: Re: GCD killed my performance
  • Previous by thread: Re: NSToolbarItem Action Not Passed to NSButton...
  • Next by thread: Re: NSToolbarItem Action Not Passed to NSButton...
  • Index(es):
    • Date
    • Thread