On Jan 6, 2013, at 6:53 PM, Arved von Brasch wrote:

> Thank you both for responding.  I am pretty sure I have everything linked up 
> properly.  I first noticed a problem when I couldn't get a NSMenuItem to 
> validate, but it seems to also be a problem with buttons.  I created a 
> NSButton subclass to test this:
> 
> @interface ABTestButton : NSButton
> @end
> 
> @implementation ABTestButton
> - (void)performClick: (id)sender {
>       NSLog(@"Perform Click!");
>       
>       NSResponder *responder = self;
>       while (responder != nil) {
>               NSLog(@"%@", responder);
>               responder = [responder nextResponder];
>               if ([responder respondsToSelector: @selector(showSettings:)])
>                       NSLog(@"Responds to 'Show Settings'!");
>       }
>       
>       [super performClick: sender];
>       
>       NSLog(@"Target: %@ Action: %@", [self target], 
> NSStringFromSelector([self action]));
>       
>       [[self target] tryToPerform: [self action] with: self];
> }
> @end

There's no reason to believe the framework calls -performClick: on a button 
when the button is clicked.  That method is for code outside of the button to 
simulate a button click programmatically.


> I then put two buttons in the base view.  One of the buttons I made an 
> ABTestButton, and connected it to the 'First Responder' object of its Xib, 
> with the action 'showSettings:'  I can see this is connected correctly in the 
> connections Tab in Xcode.  The second button I connected to the first button 
> and instructed to 'performClick:'.
> 
> Clicking the ABTestButton does not cause any debug to appear (especially not 
> the NSLog(@"Test"); in 'showSettings:').  Clicking on the other button causes 
> the following output:
> 
> 2013-01-07 11:21:12.027 Heirloom[35026:303] Perform Click!
> 2013-01-07 11:21:12.028 Heirloom[35026:303] <ABTestButton: 0x10012ac90>
> 2013-01-07 11:21:12.028 Heirloom[35026:303] <ABResponderView: 0x100132160>
> 2013-01-07 11:21:12.028 Heirloom[35026:303] <ABTabViewItemViewController: 
> 0x1030a6610>
> 2013-01-07 11:21:12.029 Heirloom[35026:303] <NSTabView: 0x10309af70>
> 2013-01-07 11:21:12.029 Heirloom[35026:303] <ABResponderView: 0x1030a57e0>
> 2013-01-07 11:21:12.029 Heirloom[35026:303] Responds to 'Show Settings'!
> 2013-01-07 11:21:12.029 Heirloom[35026:303] <ABItemsXibManager: 0x103018c70>
> 2013-01-07 11:21:12.030 Heirloom[35026:303] <NSWindow: 0x103207010>
> 2013-01-07 11:21:12.030 Heirloom[35026:303] <ABWindowController: 0x103404b60>
> 2013-01-07 11:21:12.069 Heirloom[35026:303] Target: (null) Action: 
> showSettings:
> 
> 'showSettings:' is implemented in the ABItemsXibManager class, and it clearly 
> responds to the selector as the above debug shows, but even here there is no 
> debug from it to indicate it is being called, although the function has 
> clearly been recognised on the responder chain.

You have dumped _a_ responder chain from the button up.  However, you haven't 
shown what is the _first_ responder and the chain from that.  Unless your user 
settings (in System Preferences > Keyboard) is set to allow buttons to have 
keyboard focus, the button and tab views won't be the first responder.  Unless 
some view in the window (e.g. a text field) accepts first responder (overrides 
-acceptsFirstResponder to return YES), then the window itself is likely to be 
the first responder.  Since that's above your view controller, your view 
controller won't be in the responder chain flowing from the first responder.


> As far as I can see, the validateMenuItem: method in ABItemsXibManager class 
> is never called, even though it clearly is in the responder chain.

Again, it's in _a_ responder chain, but not the one flowing from the first 
responder.

If you want a menu item to operate on something which is not chosen by the 
keyboard focus, then you should target that thing directly rather than 
targeting First Responder.

Regards,
Ken


_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to