NSSegmentedControl in a toolbar
NSSegmentedControl in a toolbar
- Subject: NSSegmentedControl in a toolbar
- From: Flavio Donadio <email@hidden>
- Date: Tue, 4 May 2010 20:54:13 -0300
Fellows,
I tried to search the list for a solution to this problem, but maybe I'm not a good searcher.
I am trying to use a NSSegmentedControl in a toolbar, capsule-styled, just like in Mail or Preview. I mean: I want each segment to have its own label, like in the "Reply / Reply All / Forward" control.
I got this sample code from the dev docs (NSToolbarItemGroup Class Reference):
// Create toolbar items
NSToolbarItem *item1 = [[[NSToolbarItem alloc] initWithItemIdentifier:@"Item1"] autorelease];
NSToolbarItem *item2 = [[[NSToolbarItem alloc] initWithItemIdentifier:@"Item2"] autorelease];
// Set items' images
[item1 setImage:[NSImage imageNamed:@"LeftArrow"]];
[item2 setImage:[NSImage imageNamed:@"RightArrow"]];
// Set items' labels
[item1 setLabel:@"Prev"];
[item2 setLabel:@"Next"];
// Create an item group and put the previously created items in it
NSToolbarItemGroup *group = [[[NSToolbarItemGroup alloc] initWithItemIdentifier:@"GroupItem"] autorelease];
[group setSubitems:[NSArray arrayWithObjects:item1, item2, nil]];
// Set the item group's view to an NSSegmentedControl instance
[group setView:someSegmentedControl];
I put the above code inside the -awakeFromNib method of my AppDelegate and then, in the header:
@interface ...
{
...
NSSegmentedControl *someSegmentedControl;
...
}
@property (nonatomic, retain) IBOutlet NSSegmentedControl *someSegmentedControl;
...
@end
Finally, in Interface Builder, I inserted an NSSegmentedControl in my toolbar and bound it to the outlet in the App Delegate instance in the NIB.
It doesn't work. My segmented control doesn't get the images or labels. Should it be done this way?
Cheers,
Flavio
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden