NSTabView question

So I’m trying to set up some code for tabView:didSelectTabViewItem: and I’m hitting a bit of a wall.

I have a tab view that’s working well, the referencing outlet is theTabView

but I think i’m failing miserably at setting up the function.

if I try:

on theTabView:didSelectTabViewItem:(tabViewItemTest)
log “click”
end didSelectTabViewItem:

it fails with “expected end of line but found “:””

If I remove theTabView, then it builds, but nothing happens. I think I’m missing something simple, but crucial. I did go over the discussion at https://macscripter.net/viewtopic.php?id=40359, but clearly, I didn’t pick up what I should have.

Have you made your script the delegate of the tab view?

Probably not? Delegates are still a little weird for me.

The tab view has a referencing outlet that I use, but I don’t think that’s what you mean.

Okay, I think i figured out what was tripping me up. I was overcomplicating things by thinking there was some great complex process instead of what was right in front of me.

ctrl-drag from the tab view to the Delegate in IB, then in the script, use the generic names for things for the “didSelectTabViewItem:tabViewItem” function, and it worked.

thanks!

well, i’m closer. I can register that there was a mouseclick on a tab, but i’m stymied on how to then get the selectedTabViewItemIndex.

on theTabView:tabView didSelectTabViewItem:tabViewItemTest
	set selectedTabViewItemIndex to tabView's indexOfTabView:tabViewItemTest
end theTabView:didSelectTabViewItem:

that works, although I wish I understood why better. One of the frustrating bits is in all the google hits I get on the subject, they all talk about “oh, just drag a tab view controller to the xib file” and of course, at least in asoc, no such love.

Looking at the code, i’m kind of like “it works, but no idea how”. I mean, I get what the function is DOING. But I have no idea why the syntax is so weird. like why I need

tabView:tabView didSelectTabViewItem:tabViewItem

specifically, why do I need two tabView’s at the beginning? I did finally dope out that in this case, tabViewItem can be replaced by sender (or probably any valid variable name) which helped a bit.

I’m also deeply confused as to selectedTabViewItemIndex. In your example, it seems to be acting as just a generic variable, but in the docs for NSTabViewController, it seems to be a property of the selected tab and should just return an index.

Controllers, like array controllers i get. A little convoluted, but I get them. Tab view controllers are just…i have no idea. Which bugs me.

(I guess if I could figure out how to create a tab view controller via code, then I’d have something tangible to work with and it might make my understanding easier. This is just…slippery)

The first one is part of the method name, and the second is a variable to hold the passed reference. You could have used whatever you like, such as:

on tabView:x didSelectTabViewItem:y

Exactly – I just used it because you used it in your message.

Honestly, I don’t think so. It’s just that delegate methods can take a while to get your head around. You’re writing code for something else to call, rather than the other way around.

I apologize for being thick here…so why doesn’t selectedTabViewItemIndex cause problems since it’s a method for NSTabViewController?

It might if you use it in the same scope as a method call of the same name, but here it’s just a local variable.

makes sense. So how would one go about using it as an actual method call on a tab view controller?

If you add a tab view controller to your xib, you’d need an outlet to it and you’d just call the method on that outlet:

set tabIndex to myTabViewController's selectedTabViewItemIndex()

But I doubt you need one. Typically they’re meant to be subclassed and are a way to separate the tab-view-related code from other code (they were only introduced in 10.10), but for ASObjC projects that tends to add a level of complexity you probably don’t want/need to deal with.

ah, and I think I’ve hit the crux of the problem. I can’t actually see a tab view controller in my list of things I can add to my xib file.

You would probably need to add a plain Object and then change its class.

Is there some place talking about how to do this?

Not to my knowledge.