Cocoa - loading a view from a nib and displaying it in a NSView container , as a subview

筅森魡賤 提交于 2019-12-06 13:24:08

Not an answer, exactly, as it is unclear what you are asking..

You make a view (class 'ImagesContainer'). Lets call it imagesContainerView.

ImagesContainerView makes 3 Objects (class 'ImageHolderNode'). ImagesContainerView asks each imageHolderNode for it's -rootView (maybe 'ImageHolderView') and adds the return value to it's view-heirarchy.

ImagesContainerView throws away (but leaks) each imageHolderNode.

So the view heirachy looks like:-

+ imagesContainerView
    + imageHolderView1 or maybe nil
    + imageHolderView2 or maybe nil
    + imageHolderView3 or maybe nil

Is this what you are expecting?

So where do you call -(void)loadUIFromNib and wait for the nib to load?
In some code you are not showing?

In general, progress a step at a time, get each step working.

NSAssert is your friend. Try it instead of mis-using alert panels and logging for debugging purposes. ie.

ImageHolderNode *node = [[[ImageHolderNode alloc] init] autorelease];
NSAssert([node rootView], @"Eek! RootView is nil.");
[self addSubview:[node rootView]];

A view of course, should draw something. TextViews draw text and ImageViews draw images. You should subclass NSView if you need to draw something other than text, images, tables, etc. that Cocoa provides.

You should arrange your views as your app requires in the nib or using a viewController or a windowController if you need to assemble views from multiple nibs. Thats what they are for.

EDIT

Interface Builder Connections

If RootView isn't nil then it seems like you have hooked up your connections correctly, but you say you are unclear so..

Make sure the IB window is set to List view so you can see the contents of you nib clearly.
'File's Owner' represents the object that is going to load the nib, right? In your case ImageHolderNode.
Control Click on File's owner and amongst other things you can see it's outlets. Control drag (in the list view) from an outlet to the object you want to be set as the instance var when the nib is loaded by ImageHolderNode. I know you know this already, but there is nothing else to it.

Doh

What exactly are you expecting to see ? An empty imageView? Well, that will look like nothing. An empty textfield? That too, will look like nothing. Hook up an outlet to your textfield and imageView and set some content on them.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!