PDA

View Full Version : NSTabView headache




ricku425
Feb 21, 2008, 02:19 PM
I am (clearly) new to Xcode/IB/Obj-C, and I am trying to write a program that uses one window and several tabs to navigate to different sections of the program. With resources such as these forums and many books on the Obj-C subject, I have been able to figure out every thing I need for the program, with the exception of one item, and that is the tabs.

I like to break things down into small programs for testing purposes, and then use those principles in the main program. So right now, I'm trying to write a simple program with two tab views and a "Button" outside of those tab views. If your in "Tab 1", and you click the Button, then "Tab 1" should show up in a text field in the tab view, and likewise, if you move to "Tab 2" and click "Button", then "Tab 2" should show up in a text field in that tab view.

So I guess my basic question is... how do you get the program to know which tab view you're in? The online documentation is very unclear on whether I use NSTabView or NSTabViewItem, and I have been unsuccessful with any of the ways I can think of to get this (what should be a) simple problem solved.

I'm not asking for anyone to write the program for me (where's the fun in that, eh?) but does anyone know of a resource they can point me to where I can learn all about how IB 3 works with XCode 3 and NSTabView(Item)?



Eraserhead
Feb 21, 2008, 03:02 PM
Use the following:


NSTabViewItem *tabViewItem=[tabView selectedTabViewItem];
if([tabViewItem isEqualTo:[tabView tabViewItemAtIndex:0]]){
//first tab view item is selected
}else{
//second tab view item is selected.
}

ricku425
Feb 21, 2008, 04:04 PM
Okay, so I tried putting that code in my program (it was very similar to what I already had, so I guess I was on the right track) I get the following warning when I compile:

"warning: 'NSTabViewItem' may not respond to '-selectedTabViewItem'
(Messages without a matching method signature will be assumed to return 'id' and accept '...' as arguments.)"

as well as:

"warning: 'NSTabViewItem' may not respond to '-tabViewItemAtIndex.'"

and then nothing happens in the program. I think in the @interface section I need to have something like the following:

-(void)tabView:(NSTabView *)tabView didSelectTabViewItem:(NSTabViewItem *)tabView;

but I am unsure if this is correct or not as it also produces errors. Something tells me I also might be doing something wrong in IB. My outlets are defined as the following:

IBOutlet NSTabView *tab1; //The left tab.
IBOutlet NSTextView *tab1Text; //The text field under Tab1.
IBOutlet NSTabView *tab2; //The right tab.
IBOutlet NSTextView *tab2Text; //The text field under Tab2.
IBOutlet NSTabViewItem *tabView; //Where Tab1 and Tab2 live.

phjo
Feb 21, 2008, 04:42 PM
You're obviously confusing the roles of NSTabView and NSTabViewItem

Left and right tab should be NSTabViewItem

and the view with the two tabs should be a NSTabView (which <<contains>> the two NSTabViewItem you need...)

phjo

ricku425
Feb 21, 2008, 05:28 PM
Oh... my... God... :eek:

*Smack his hand so hard to his forehead that he gets knocked out for an hour*

I cannot believe what an idiot I am sometimes... :mad:

Thanks for showing me the light...