NSToolbar

That's because you are meant to programmatically instantiate it. That's why the article is so long and goes into so much detail :).
 
I don't see what you're complaining about. Did you come from a Delphi or VB background?
 
Draws are pretty easy: http://developer.apple.com/document...wers/index.html#//apple_ref/doc/uid/10000001i

Toolbars are easy once you do a few of them, you just can't do them in Interface Builder for whatever reason. The documentation from Apple looks overwhelming, but check out: http://www.cocoadevcentral.com/articles/000037.php

Here's some code from my app (I removed unnecessary code to make it shorter):

Code:
#define TOOLBAR_IDENTIFIER		@"Main toolbar"
#define PREV_BUTTON				@"Previous button"
#define	NEXT_BUTTON				@"Next button"
#define TRASH_BUTTON			@"Delete button"
#define TAG_BUTTON				@"Tag button"
#define REMOVE_BUTTON			@"Remove Button"
#define SHRINK_BUTTON			@"Shrink Button"
#define INFO_BUTTON				@"Get Info Button"

@implementation ToolbarController


- (NSArray *)toolbarAllowedItemIdentifiers:(NSToolbar *)toolbar
{
	NSArray * toolBarIdentifiers = [NSArray arrayWithObjects:
		PREV_BUTTON,
		NEXT_BUTTON,
		TRASH_BUTTON,
		TAG_BUTTON,
		REMOVE_BUTTON,	
		SHRINK_BUTTON,
		INFO_BUTTON,
		NSToolbarSpaceItemIdentifier,
		NSToolbarSeparatorItemIdentifier,
		NSToolbarFlexibleSpaceItemIdentifier,
		NSToolbarCustomizeToolbarItemIdentifier,
		nil];
	
	return toolBarIdentifiers;
}


- (NSArray *)toolbarDefaultItemIdentifiers:(NSToolbar *)toolbar
{
	NSArray * defaultItems = [NSArray arrayWithObjects:
		PREV_BUTTON,			
		NEXT_BUTTON,
		TAG_BUTTON,
		INFO_BUTTON,
		NSToolbarSeparatorItemIdentifier,
		SHRINK_BUTTON,
		NSToolbarFlexibleSpaceItemIdentifier,
		REMOVE_BUTTON,
		TRASH_BUTTON,
		nil];
	
	return defaultItems;
}



- (NSToolbarItem *)toolbar:(NSToolbar *)toolbar itemForItemIdentifier:(NSString *)itemIdentifier willBeInsertedIntoToolbar:(BOOL)flag
{
	NSToolbarItem * item = [[NSToolbarItem alloc] initWithItemIdentifier:itemIdentifier];
	
		
	if ( [itemIdentifier isEqualToString:SHRINK_BUTTON] ) {
		[item setImage:[NSImage imageNamed:@"Shrink.png"]];
		[item setLabel:@"Full Screen"];
		[item setPaletteLabel:@"Toggle Full Screen"];
		[item setAction:@selector(toggleFullScreen:)];
		[item setToolTip:@"Switch to full screen mode"];
		[item setTarget:nil];
	}
	if ( [itemIdentifier isEqualToString:INFO_BUTTON] ) {
		[item setImage:[NSImage imageNamed:@"info.icns"]];
		[item setLabel:@"Image Info"];
		[item setPaletteLabel:@"Image Info"];
		[item setAction:@selector(getImageInfo:)];
		[item setToolTip:@"Get image info"];
		[item setTarget:nil];
	}
	
	return [item autorelease];
}

@end

nil targeted actions behave like menu items... they target the first responder and then work back up the responder chain, so they're more flexible than setting a specific target.
 
Viro: Started in BASIC on the Commodore 64, then QBasic on DOS, then VB on Windows - was NOT impressed, moved to Delphi about 4 years ago, been there since.

btoth: Thanks for the example, I'll have a bash at a toolbar tonight. Really disappointed you have to do it all in code, though.
 
Yeah, everything I've ever used that's got an IDE to make the interface includes toolbars in that, seeing as they're visual controls. Ah well. Yet something else to get used to :)
 
Back
Top