How do I validate an NSButton in an NSToolbar?
<p>I have a document-based app with a tool bar containing several NSButton which I need to validate. Base on other code here, I have subclassed NSToolbar:</p>

<pre><code>@interface CustomToolbar : NSToolbar
@end
@implementation CustomToolbar
-(void)validateVisibleItems
{
    for (NSToolbarItem *toolbarItem in self.visibleItems)
    {
        NSResponder *responder = toolbarItem.view;
        while ((responder = [responder nextResponder]))
        {
            if ([responder respondsToSelector:toolbarItem.action])
            {
                [responder performSelector:@selector(validateToolbarItem:) withObject:toolbarItem];
            }
        }
    }
}
@end
</code></pre>

<p>MyDocument (the File's owner) is set as the delegate of the toolbar. However</p>

<p>-(BOOL)validateToolbarItem:(NSToolbarItem *)toolbarItem </p>

<p>is never called. The buttons have an action set on them, so not sure why [responder respondsToSelector:toolbarItem.action] is always false.</p>

<p>I have tried subclassing the NSButton items:</p>

<pre><code>@interface DocumentToolbarActionItem : NSToolbarItem

@implementation DocumentToolbarActionItem

-(void)validate
{
    Document* document = [[self toolbar] delegate];
    [self setEnabled:[document validateUserInterfaceItem:self]];
}

@end
</code></pre>

<p>But this results in an endless loop.</p>

<p>The document's validateUserInterfaceItem: method works for all other items in the app and I need to have my toolbar button call it to determine if they should be enabled or not.</p>