Xcode help, setting an NSTabViewItem outlet

Discussion in 'Mac Apps and Mac App Store' started by FredAkbar, Aug 19, 2004.

  1. FredAkbar macrumors 6502a

    FredAkbar

    Joined:
    Jan 18, 2003
    Location:
    Santa Barbara, CA
    #1
    Okay, I'm a little bit new to Cocoa but I pretty much have all the interface builder (and corresponding code) down, and I understand targets and outlets and all that. Here's my problem. I have a window with a few tabs (by default, each tab is an NSTabViewItem of the overall NSTabView). I want to make one (or all, or whatever) of the tabs (instances of NSTabViewItem) an outlet of one of my custom classes.

    So I added the variable in my code, parsed the .h file into Interface Builder, so that the outlet shows up in my class info...and I know that I should now control-drag from my class instance to the NSTabViewItem to connect the outlet...but I can't figure out how to do it. I can easily drag to the NSTabView itself, but I can't get it to drag to the NSTabView item. I've tried clicking on the tab name so that it's blue with kind of a blurry highlight around it (completely selected, the Inspector window says NSTabViewItem and everything), but even then, when I control-drag from the class instance to it, it thinks I'm dragging to the NSTabView, so it won't let me connect it (I've confirmed that this is what it's thinking, because when I do that and try to connect it to an NSTabView outlet, it works). How can I make this outlet to the tab itself (the NSTabViewItem instance)? There doesn't seem to be any way (like menu-based or something) to connect an outlet other than control-dragging. It always works fine, but not here. Help?

    Thanks.
     
  2. HexMonkey Administrator

    HexMonkey

    Staff Member

    Joined:
    Feb 5, 2004
    Location:
    New Zealand
    #2
    Here's one way to do it, there may be others:

    Select the Instances tab of the nib document window. Change it's view from icon view to list view using the icons at the top of the vertical scroll bar. Then expand the appropriate items until you can find the NSTabView (first expand the window, then it's content view, then the NSTabView if it's not nestled inside other views). Once that's expanded, you'll see a list of each of the tab view items. You can now just control-drag from the class instance to the NSTabViewItems in the list to connect them.

    Alternatively, instead of using outlets for each tab view item, you can get references to them in code if you have references to the NSTabView that contains them. Check the documentation for NSTabView, methods such as -tabViewItems and -tabViewItemAtIndex: could be of use. Depending on what you're doing, you might be able to avoid using references to the tab view items altogether using the methods in NSTabView.
     
  3. FredAkbar thread starter macrumors 6502a

    FredAkbar

    Joined:
    Jan 18, 2003
    Location:
    Santa Barbara, CA
    #3
    Yay, thanks man, I totally forgot that I could change it from an icon view to a list view.

    Oh yeah that's true, huh, I can just say NSTabViewItem *myTab = [myTabView tabViewItemAtIndex:2] or whatever, I think I was having a brain fart and when I saw in the Docs that tabViewItemAtIndex returned an NSTabViewItem, I was like "well I don't know how to access any of those" even though that's how you do it. I guess what I wanted was something like "if ([myTabView selectedTabIndex] == 2)..." but there doesn't seem to be anything like that, but your ideas will work just as well.

    Anyway, thanks again for the help.
     
  4. HexMonkey Administrator

    HexMonkey

    Staff Member

    Joined:
    Feb 5, 2004
    Location:
    New Zealand
    #4
    Something like this should work:
    Code:
    if ([myTabView indexOfTabViewItem:[myTabView selectedTabViewItem]] == 2)
    ...
     
  5. FredAkbar thread starter macrumors 6502a

    FredAkbar

    Joined:
    Jan 18, 2003
    Location:
    Santa Barbara, CA
    #5
    Ah nice, once again I didn't bother to have my thinking cap on...thanks! :)
     

Share This Page