Challenge 2: disable menu item


#1

Challenge 2 is working fine. However it would be nice to disable the ‘Remove Employee’ menu item when there are zero employees in the tableView. This is how the ‘Delete’ button works by binding to the ArrayController’s canRemove Controller Key.
I’ve been trying to bind it to an ArrayController pointing to the employees array in the MainMenu.xib doc window, but there there is an uncaught exception at app launch. So both MyDocument.xib and MainMenu.xib each have array controllers pointing to employees. What am I missing? Or is there a way to bind between .xib’s?

Thanks,
Glenn


#2

Rusty’s solution on the old pages:
techstra.bignerdranch.com/Home

page 294 should do the trick.

Helps???
Ian


#3

Excellent, thanks IanDMah. I didn’t know about http://techstra.bignerdranch.com/Home; great resource.

I worked from the solution given by [quote]mdeh said the following on Feb 1, 2010:[/quote] since ‘validateMenuItem:’ has been depreciated.

And since this is an informal protocol, I didn’t bother with the super call. In fact I don’t think it should be made here if I’m understanding how categories are used. However, if the method ‘validateUserInterfaceItem:’ was overridden in its implementation, I would have made the super call.

Any thoughts on this?

- (IBAction)removeEmployeeByMenuItem:(id)sender
{
	[self removeEmployee:sender];
}

- (BOOL)validateUserInterfaceItem:(id <NSValidatedUserInterfaceItem>)anItem
{
	SEL selector = [anItem action];
	if (selector == @selector(removeEmployeeByMenuItem:) && [tableView selectedRow] >= 0)
	{
		return YES;
	}
	
	return NO;
}

#4

Actually, after re-reading the documentation, I think this is properly termed simply a ‘protocol’. However, I still conclude that the super call shouldn’t be there.