Zero Tabs in TabView in Cocoa

Discussion in 'Mac Programming' started by gamestriker, Aug 11, 2005.

  1. gamestriker macrumors regular

    Joined:
    Dec 18, 2004
    #1
    I've been learning cocoa recently through Apple's documentation and a variety of other sources. To really test out what I have learned, I'm rewriting one of my private java apps into Cocoa with Objective C. So far I got about 30% done but I've run into a wall. In the program, the JTabbedPane (the java equivalent of NSTabView) starts out with no tabs and you could open up text files in multiple tabs. However, I can't seem to get an NSTabView to have 0 tabs. Does anyone know how to make 0 tabs be a valid state in NSTabView?

    I'm also not exactly sure how to put an NSTextView with a file into that tab when it opens up. I'm pretty sure I'd have to do that through a custom controller though. Can anyone help me with this?

    I appreciate the help :)
     
  2. ravenvii macrumors 604

    ravenvii

    Joined:
    Mar 17, 2004
    Location:
    Melenkurion Skyweir
    #2
    Before I start: I'm no coder.

    But I've never seen a tabs view in OS X without any tabs. Maybe they're indeed not possible. BUT they can be activated and unactivated (take Safari for a example). So perhaps you can create a space in the window where the tabs would be, and leave it blank. And when a new tab is requested, the program would automatically "activate" the tabs view, in the same space where the blank space was before. It'll look like it's there all along... know what I'm saying?

    Again, I'm no coder, so I don't know how easy/hard that would be.
     
  3. gamestriker thread starter macrumors regular

    Joined:
    Dec 18, 2004
    #3
    Their might be something like that, though I'm not sure how to make it work.
     
  4. HiRez macrumors 603

    HiRez

    Joined:
    Jan 6, 2004
    Location:
    Western US
    #4
    InterfaceBuilder won't let you show 0 tabs, but you can do it programmatically. Somewhere, probably in your windowControllerDidLoadNib: method (you cannot do this in an init: method as the UI objects will not be valid yet), do:
    Code:
    	[tabView setTabViewType:NSNoTabsBezelBorder];
    Then when the first tab is to be added:
    Code:
    	[tabView setTabViewType:NSTopTabsBezelBorder];
    You will of course have to specify your tab view as an IBOutlet in your header file and connect it in IB. There are other constants for other tab styles, see the NSTabView documentation for details.

    EDIT: this might be the same as specifying "Tabless" style in IB, in that case maybe you could skip the first code step.
     
  5. HiRez macrumors 603

    HiRez

    Joined:
    Jan 6, 2004
    Location:
    Western US
    #5
    Once you've created your text view, you can add the tab view and item something like this:
    Code:
    NSTabViewItem *newItem = [[NSTabViewItem alloc] initWithIdentifier:@"My New Tab"];
    [newItem setView:myTextView]; //view is retained by the tab view item
    [tabView addTabViewItem:newItem];
     

Share This Page