我有一个NSTabView,我在其中分配和加载相同的NSViewController:

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


如何在每个IRCView选项卡上加载NSTabView视图控制器的不同“实例”?因此,每个标签都可以与IRC服务器建立不同的连接(在此示例中)

最佳答案

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
}

07-26 09:38