• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Add Toolbar to Document Based Project
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Add Toolbar to Document Based Project


  • Subject: Add Toolbar to Document Based Project
  • From: Uwe Schlosser <email@hidden>
  • Date: Sat, 30 Nov 2002 18:24:54 +0100

I would like to add a toolbar to a document based application. I chose
an approach similar to an example by Mike Beam Creating Toolbars for
Mac OS X.
I extended the class "MyDocument" by the Category
(ToolbarDelegateCategory).

@interface MyDocument (ToolbarDelegateCategory)

-(NSToolbarItem *)toolbar:(NSToolbar *)toolbar
itemForItemIdentifier:(NSString *)itemIdentifier
willBeInsertedIntoToolbar:(BOOL)flag;

-(NSArray *)toolbarAllowedItemIdentifiers:(NSToolbar*)toolbar;

-(NSArray *)toolbarDefaultItemIdentifiers:(NSToolbar*)toolbar;

-(void)setupToolbar;
@end

I did also the implementation for this category. Important is the
method:

-(void)setupToolbar
{
NSToolbar *toolbar =[[NSToolbar alloc]
initWithIdentifier:@"mainToolbar"];
[toolbar setDelegate:self];
[toolbar setAllowsUserCustomization:YES];
[toolbar setAutosavesConfiguration:YES];
[window setToolbar:[toolbar autorelease]];
}

The problem is setting up the toolbar in the document window by the
method
[window setToolbar: toolbar];
The instance variable window is declared as private in NSDocument, so
there is no direct access in MyDocument.

I worked a round this problem by defining a second a second instance
variable
IBOutlet id docWindow

and did the the right connection in IB. After replacing window by
docWindow and compiling the code the application works fine.
In the end I use to instance variable for one object and that a bit
strange.
My question is, is this the only way to work around such a problem.

Thanks for any help!

Uwe
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

  • Follow-Ups:
    • Re: Add Toolbar to Document Based Project
      • From: Fritz Anderson <email@hidden>
    • Re: Add Toolbar to Document Based Project
      • From: j o a r <email@hidden>
  • Prev by Date: superclass and awakeFromNib
  • Next by Date: Problem with object communication
  • Previous by thread: Re: superclass and awakeFromNib
  • Next by thread: Re: Add Toolbar to Document Based Project
  • Index(es):
    • Date
    • Thread