View Full Version : Zero Tabs in TabView in Cocoa
gamestriker
Aug 11, 2005, 09:06 PM
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 :)
ravenvii
Aug 11, 2005, 10:05 PM
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.
gamestriker
Aug 11, 2005, 11:11 PM
Their might be something like that, though I'm not sure how to make it work.
HiRez
Aug 11, 2005, 11:54 PM
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: [tabView setTabViewType:NSNoTabsBezelBorder];Then when the first tab is to be added: [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.
HiRez
Aug 12, 2005, 12:09 AM
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?
Once you've created your text view, you can add the tab view and item something like this:NSTabViewItem *newItem = [[NSTabViewItem alloc] initWithIdentifier:@"My New Tab"];
[newItem setView:myTextView]; //view is retained by the tab view item
[tabView addTabViewItem:newItem];
vBulletin® v3.8.6, Copyright ©2000-2013, Jelsoft Enterprises Ltd.