How to use tabbar in mac Application

886 views Asked by At

i am trying to develop mac application(cocoa app).i have successfully used tabbar in iphone app. but in developing mac application ,how to use tabbar?

As we use tabbar for iphone application,i want to implement same kind of functionality for Mac App(cocoa app).

any idea?how its possible?

1

There are 1 answers

0
Roger On

I presume you are talking about an NSTabView when you refer to "tabbar" or "Tababr"...

You do not need to write your whole app in one AppDelegate.

You can add your AppDelegate as a delegate of your NSTabView and then implement tabView:didSelectTabViewItem:. This allows you to intercept requests by the user for different tabs. Just create an outlet for your tab view and set the delegate:

[[self tabView] setDelegate: self]

Based on the requested tab you can then create the view controller associated with that tab and load the NSView into the selected tab. Something like:

- (void)tabView:(NSTabView *)tabView didSelectTabViewItem:(NSTabViewItem *)tabViewItem {

  MyViewController aController = [[MyViewController alloc]
    initWithNibName: @"MyView" bundle: [NSBundle mainBundle]];
  [tabviewItem setView: [aController view]];

}

I'm not sure whether you need to add NSTabViewDelegate as a protocol to your AppDelegate but if Xcode flags a warning you'll notice:

@interface MyAppDelegate : NSApplicationDelegate <NSTabViewDelegate>

Hope this helps. Otherwise you need to elaborate on your requirements.