Note that there are some explanatory texts on larger screens.

plurals
  1. POprogrammatically loading object from subclass of NSView from nib
    primarykey
    data
    text
    <p>How do I correctly load an object that is a subclass of NSView using a Xib?</p> <p>I want it to be loaded dynamically not from the beginning so I made a MyView.Xib From MyDocument.m I did:</p> <pre><code>MyView *myView = [[MyView alloc] initWithFrame:...]; [NSBundle loadNibNamed:@"MyView" owner:myView]; [someview addSubview:myView]; ... </code></pre> <p>and the background is fine (it calls drawrect: and it's drawn as expected) but all the buttons I put on the xib won't appear. I have checked, and they are loaded BUT their superview is not the same object as <code>myView</code>.</p> <p>Why is this? I think I am missing something in the Xib but I don't know exactly what. In other words: How do I make sure that the root view in my xib is the same object as file's owner?</p> <p>I wish there was something similar to this for the mac:</p> <pre><code>NSArray* nibViews = [[NSBundle mainBundle] loadNibNamed:@"MyView" owner:self options:nil]; //in iOS this will load the xib MyView* myView = [ nibViews objectAtIndex:1]; [someview addSubview:myView]; ... </code></pre> <p>Thanks in advance.</p> <p><strong>EDIT</strong></p> <p>I think I have realised the origin of the problem...(??)</p> <p>In MyView class I have various IBOutlet which are connected correctly in IB that is why they load just fine (I can refer them). However there is no IBOutlet for the top view. So when NSBundle loads the nib, the top view gets assigned to some other object. I thought this will happen if I set my top view in IB to be from class:<code>MyView</code> and put <code>myView</code> as the owner in <code>[NSBundle loadNibNamed:@"MyView" owner:myView];</code> but it seems not to be the case. What am I doing wrong?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload