Re: NSViewController in the responder chain
Re: NSViewController in the responder chain
- Subject: Re: NSViewController in the responder chain
- From: Arved von Brasch <email@hidden>
- Date: Mon, 07 Jan 2013 11:53:01 +1100
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
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.
ABResponderViews are my custom view subclasses (at the moment exactly the same as in the Cocoa With Love example). These are the top level views of Xib files, owned by NSViewController subclasses.
ABTabViewItemViewController and ABItemsXibManager are both NSViewController subclasses, that own the ABResponderViews.
As far as I can see, the validateMenuItem: method in ABItemsXibManager class is never called, even though it clearly is in the responder chain. At present, my application only has a single window. 'showSettings:' is the action I was trying to connect to a menu item. (If I can get 'showSettings:' to be called, that'll be the second window.)
On 2013-01-07, at 03:23 , Andy Lee <email@hidden> wrote:
> Yup, and you could also double-check the nib to make sure the action is connected to First Responder. If the button is in the nib and the view controller is File's Owner, you could connect directly to File's Owner and avoid searching the responder chain at all. Menu items would still have to connect to First Responder though.
Yeah, that might be a solution, but I'd still like to understand why this doesn't work. From everything I've read, what I'm doing should be possible, and I know others do it, but I can't see where I could possibly be going wrong. This is 10.8 (and I'm not supporting any previous OSes) and everything is up-to-date, if that could make a difference.
Arved
_______________________________________________
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