在NSViewcontroller中使用xib加载NSView

时间:2016-08-19 09:12:58

标签: objective-c macos nsview custom-view nsviewcontroller

如何在我的NSViewController中使用xib加载NSView?我想在三个以上的nsviewcontroller(位置)中重用自定义nsview和xib。 如何在nsviewcontroller中加载nsview xib

帮我解决这个问题。

提前致谢。

1 个答案:

答案 0 :(得分:0)

试试这个:

+ (NSView *)loadWithNibNamed:(NSString *)nibNamed owner:(id)owner class:(Class)loadClass {

    NSNib * nib = [[NSNib alloc] initWithNibNamed:nibNamed bundle:nil];

    NSArray * objects;
    if (![nib instantiateWithOwner:owner topLevelObjects:&objects]) {
        NSLog(@"Couldn't load nib named %@", nibNamed);
        return nil;
    }

    for (id object in objects) {
        if ([object isKindOfClass:loadClass]) {
            return object;
        }
    }
    return nil;
}

来自repo