Next Page > Hide TOC

NSMenuValidation Protocol Reference

(informal protocol)

Framework
/System/Library/Frameworks/AppKit.framework
Companion guide
Declared in
NSMenu.h

Overview

This informal protocol allows your application to update the enabled or disabled status of an NSMenuItem object. It declares only one method, validateMenuItem:.

Tasks

Validating Menu Items

Instance Methods

validateMenuItem:

Implemented to override the default action of enabling or disabling a specific menu item.

- (BOOL)validateMenuItem:(NSMenuItem *)menuItem

Parameters
menuItem

An NSMenuItem object that represents the menu item.

Return Value

YES to enable menuItem, NO to disable it.

Discussion

The object implementing this method must be the target of menuItem.You can determine which menu item menuItem is by querying it for its tag or action.

The following example disables the menu item associated with the nextRecord action method when the selected line in a table view is the last one; conversely, it disables the menu item with priorRecord as its action method when the selected row is the first one in the table view. (The countryKeys array contains names that appear in the table view.)

- (BOOL)validateMenuItem:(NSMenuItem *)item {
    int row = [tableView selectedRow];
    if ([item action] == @selector(nextRecord) &&
        (row == [countryKeys indexOfObject:[countryKeys lastObject]])) {
        return NO;
    }
    if ([item action] == @selector(priorRecord) && row == 0) {
        return NO;
    }
    return YES;
}
Availability
Declared In
NSMenu.h

Next Page > Hide TOC


© 2007 Apple Inc. All Rights Reserved. (Last updated: 2007-03-02)


Did this document help you?
Yes: Tell us what works for you.
It’s good, but: Report typos, inaccuracies, and so forth.
It wasn’t helpful: Tell us what would have helped.