Question

I'm trying to replace the deprecated

[NSBundle loadNibNamed:@"Subscriptions" owner:self];

with this instead (only thing I can find that's equivalent)

[[NSBundle mainBundle] loadNibNamed:@"Subscriptions" owner:self topLevelObjects:nil];

but the dialog pops up and disappears right away instead of staying open like it was doing with the deprecated call.

This code is inside a viewcontroller like this.

- (id)init{
    self = [super init];
    if (self) {
        //[NSBundle loadNibNamed:@"Subscriptions" owner:self];

        [[NSBundle mainBundle] loadNibNamed:@"Subscriptions" owner:self topLevelObjects:nil];
    }
    return self;

}

and I'm calling it from the appdelegate like this.

SubscriptionsViewController *subscriptionsViewController = [[SubscriptionsViewController alloc] init];
[subscriptionsViewController.window makeKeyAndOrderFront:self];

Is there anything I'm missing? It seems straight forward to me.

Was it helpful?

Solution

The dialog appearing and then disappearing is a sign of possible object collection - with a strong reference to the dialog it will be collected and lost.

The deprecated call retained ownership of the top-level objects in the nib, the new call does not.

Therefore the properties of the owner object that refer to top-level objects must be strong, or you need to keep the top-level objects array. This is contrary to the old recommendation where such properties were weak.

Properties which reference non-top-level objects in the nib can still be weak.

OTHER TIPS

I just had a similar problem when using loadNibNamed: owner: topLevelObjects: and always got an error like

[__NSArrayM insertObject:atIndex:]: object cannot be nil' terminating with uncaught exception of type NSException abort() called

Because my top level objects where nil.

I finally discovered that the nib file I was loading had its Interface Builder version set to "Xcode 4.6". When I set that to 6.2, everything worked fine again.

enter image description here

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top