I have two nib files, one that will open at startup and another that will be loaded when a user clicks a button. The first one works fine, and the second one works the first time. The thing is that I want to load the second nib file several times separately whenever the button is pressed. Currently I’m using this:
- (IBAction)startAction:(id)sender {
NSNib *nib = [[NSNib alloc] initWithNibNamed:@"SecondView" bundle:nil];
[nib instantiateNibWithOwner:self topLevelObjects:nil];
But this reloads the nib that is already being shown, I want a new view to be loaded separately. They each display some user input which will be different for each view loaded, so I imagine it has to be made into separate objects so they don’t interfere with one another. I can tell the nib is being loaded because a timer is displayed, and every time enter is pressed the timer counts faster, meaning they’re running simultaneously on the same view, I want them running simultaneously on separate views. I found the code I’m using in the documentation, but it had this written under it:
// At this point, our outlets to inside this nib will be properly setup. It is important to note
// that they will get overwritten when this is called again!
So I’m not sure if what I want can be done using this code, or if I should use something completely different.
Thanks for the help!
After the nib file has been loaded, the
NSNibobject uses the bundle’s resource map to locate additional resources referenced by the nib. If you specifiednilfor the bundle parameter, theNSNibobject looks for those resources in the bundle associated with the class of the nib file’s owner instead. You should instantiating your nib with different owner object.