在NSTabView上加载相同NSViewController的不同实例

时间:2011-11-12 14:46:25

标签: macos cocoa nsview viewcontroller nstabview

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

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

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

1 个答案:

答案 0 :(得分:0)

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
}