NSTabView select a tab

Hi

I am trying to use a delegate method tabView:shouldSelectTabViewItem: so when a tab is selected, the view that contains whatever type of objects can return results for me. From the documentations, it state:

Invoked just before tabViewItem in tabView is selected.

  • (BOOL)tabView:(NSTabView *)tabView shouldSelectTabViewItem:(NSTabViewItem *)tabViewItem

When I run the app, the console does not show any reference to processing the method. Is there something else I need to do, or my understanding of “Invoked” is not correct.

Please provide me with some code if possible

Thanks,
t.

Hi,

all should. methods which return a boolean value are a programmatically “The [object] will be [whatever] right now. Do you really want to give permission to that?”
If you return YES, the tab view will be selected in this case.
If you return NO, it won’t.

A good example is applicationShouldTerminateAfterLastWindowClosed.
The method is invoked after the last window has been closed.
Returning YES terminates the app, NO does nothing.

Thank you Stefan. In that case, I should create separate handlers for each tab and implement the appropriate instance class method.

Regards,
t.

No, you need just one handler in the tab view’s delegate. Then you can check the value of the second argument (tabViewItem), to see which tab is involved.

Hi Shane,

I guess you are referring to the delegate method tabView_didSelectTabViewItem_(tabView, tabViewItem), where tabView is the property in IB connected to the tabView, and tavViewItem being the selected tab.

on tabView_didSelectTabViewItem_(tabView, tabViewItem)
	log log tabViewItem's |identifier|()
end tabView_didSelectTabViewItem_

This is not producing any results in the console. It appears that the delegate method isn’t getting processed. I know I can access the tabs from a separate handlers and I can identify them using selectTabViewItemAtIndex_(1)

Any hep is very much appreciate Shate.

Regards,
t.

It should work with any of the delegate methods.

Have you set the tab view’s delegate?

Thank you Shane for pointing this out to me. It works now.

Best Regards,
t.

HI Shane,

I implemented a handler in one of the tabs and it works perfectly. In the second tab, I have a tableView with two columns which I have already working in a separate app using NSTableViewDataSource. The methods I use are as follow:

  • (NSInteger)numberOfRowsInTableView:(NSTableView *)aTableView
    return something’s |count|()

  • (id)tableView:(NSTableView *)aTableView objectValueForTableColumn:(NSTableColumn *)aTableColumn row:(NSInteger)rowIndex
    – code to load parameters in each column.

How do I call these two methods from within:

on tabView_didSelectTabViewItem_(tabView, tabViewItem)
log log tabViewItem’s |identifier|()
end tabView_didSelectTabViewItem_

Regards,
t.

these table view delegate methods are called automatically while the table view is going to reload the table view data or when you invoke explicitly the reloadData method

In numberOfRowsInTableView you have to return the number of items in the collection object,
normally [collection count]
In objectValueForTableColumn you have to return the object for the specified row and column,
normally [[collection objectAtIndex:row] objectForKey:[aTableColumn identifier]] assuming the collection array contains dictionary objects.

Hi Stefan,

I already have these two methods working in a separate app. In the tabView app that I am working on, I am using the method which I listed below. How do I reference the second if statement which corresponds to the second tab to load or call the table methods? By the way, I am obtaining initial data from awakeFromNib() which I am using later to populate the table based upon the tableColumn’s identifiers.

on tabView_didSelectTabViewItem_(tabView, tabViewItem)
if tabViewItem’s |identifier|() isEqualToString_(“Table”) then
– hare I want to call the table methods
end if
end tabView_didSelectTabViewItem_

Please note that XCODE does not even allow me to place the methods within the if statement.

Regards,
t.

call theTableView’s reloadData() (theTableView is the reference to the NSTableView instance)

Thanks Stefan, I got it to work.

Regards,
t.

Hi All,

Mac OS uses tabViews extensively in System Preferences, yet I haven’t been able to find books that cover this Class Method in detail. Does anyone know of Cocoa books that cover this topic.

Regards,
t.

Have you searched the docs for ‘Introduction to Tab Views’?