Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

gamestriker

macrumors regular
Original poster
Dec 18, 2004
174
0
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

macrumors 604
Mar 17, 2004
7,585
492
Melenkurion Skyweir
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.
 

HiRez

macrumors 603
Jan 6, 2004
6,250
2,576
Western US
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.
 

HiRez

macrumors 603
Jan 6, 2004
6,250
2,576
Western US
gamestriker said:
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:
Code:
NSTabViewItem *newItem = [[NSTabViewItem alloc] initWithIdentifier:@"My New Tab"];
[newItem setView:myTextView]; //view is retained by the tab view item
[tabView addTabViewItem:newItem];
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.