Search code examples
macoscocoansviewviewcontrollernstabview

LOad different instances of the same NSViewController on NSTabView


I have a NSTabView, where I alloc and load the same NSViewController on its tabs:

IRCView *viewirc = [[IRCView alloc] initWithNibName:@"IRCView" bundle:nil];
for (id view in [tabsView tabViewItems]) {
     [view setView:[viewirc view]];
}

How could I load different 'instances' of IRCView view controller on each of the NSTabView tabs? So each tab can have a different connection to the IRC server (in this example)


Solution

  • for(NSTabViewItem * tabViewItem in [tabsView tabViewItems])
    {
        // instantiate a brand new IRCView for each tab view item...
        IRCView *viewirc = [[IRCView alloc] initWithNibName:@"IRCView" bundle:nil];
    
        // ... and do whatever customization you want to do for each IRCView here
    
        [tabViewItem setView: viewirc];
        [viewirc release]; // tabViewItem already retains
    }