---
title: "validateToolbarItem:"
framework: objectivec
role: symbol
role_heading: Instance Method
path: "objectivec/nsobject-swift.class/validatetoolbaritem:"
---

# validateToolbarItem:

If this method is implemented and returns false, NSToolbar will disable theItem; returning true causes theItem to be enabled.

## Declaration

```occ
- (BOOL) validateToolbarItem:(NSToolbarItem *) item;
```

## Discussion

Discussion NSToolbar only calls this method for image items. note: validateToolbarItem: is called very frequently, so it must be efficient. If the receiver is the target for the actions of multiple toolbar items, it’s necessary to determine which toolbar item theItem refers to by testing the itemIdentifier. -(BOOL)validateToolbarItem:(NSToolbarItem *)toolbarItem {     BOOL enable = NO;     if ([[toolbarItem itemIdentifier] isEqual:SaveDocToolbarItemIdentifier]) {         // We will return YES (enable the save item)         // only when the document is dirty and needs saving         enable = [self isDocumentEdited];     } else if ([[toolbarItem itemIdentifier] isEqual:NSToolbarPrintItemIdentifier]) {         // always enable print for this window         enable = YES;     }     return enable; }

## See Also

### Related Documentation

- [validateVisibleItems()](appkit/nstoolbar/validatevisibleitems().md)
- [action](appkit/nstoolbaritem/action.md)
- [target](appkit/nstoolbaritem/target.md)
- [Toolbar Programming Topics for Cocoa](apple-archive/documentation/Cocoa/Conceptual/Toolbars.md)
- [validate()](appkit/nstoolbaritem/validate().md)
