gargantuan
gargantuan

Reputation: 8944

How do create a one window app with cocoa and interface builder?

I'm just starting out with interface builder and I'd like to create a tabbed, single window app similar in design to Coda or Versions.

However, i can't figure out what approach I should be taking. I think I'll probably need to create my own tab bar and some sort of controller to load/unload different 'views', but what should the individual 'views' be?

Is it a case of creating multiple windows and somehow loading them up in a parent window, or should I be toggling the visibility of a bunch of custom views, or is there a completely different approach?

Upvotes: 1

Views: 868

Answers (2)

radex
radex

Reputation: 6536

That's how i did that:

For each view I made separate nibs, and ViewController (SomethingViewController:NSViewController). In nibs I set "File's owner" to SomethingViewController.

View controller automatically loads nib:

- (id) init
{
   if(self = [super initWithNibName:@"HistoryTab" bundle:nil])
   {
      [self loadView];
   }

   return self;
}

And I just create instance of ViewController.

To create tabs like in Coda you'll need to write some code or use BWToolkit

Sorry for my English ;)

Edit:

I would forgot - in main window I have mainView view, and after loading ViewController I just do in app controller:

[self.mainView addSubview:[viewController view]];

and when switching tab I:

[[viewController view] removeFromSuperlayer];

Upvotes: 2

Nikolai Ruhe
Nikolai Ruhe

Reputation: 81868

The standard approach to switch between a set of views in Cocoa is to use a NSTabView. You can setTabViewType: to NSNoTabsNoBorder to hide the tabs completely and use the tab view only for switching your views. If you put the tab view into the window’s content view, and adjust auto resizing, the tab view switches the whole window contents.

You can use customized toolbar items to activate individual tabs.

Upvotes: 3

Related Questions