5

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.

Ryan Knopp
  • 582
  • 1
  • 4
  • 12

2 Answers2

1

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.

CRD
  • 52,522
  • 5
  • 70
  • 86
  • so what could be the solution, i have the outlet is strong but its still hiding – Retro Jan 03 '14 at 11:07
  • @Retro - It sounds like you have a different problem, if you have a strong reference the object won't be collected. Ask your own question, giving details of your code, what goes wrong and what you've tried - then someone might be able to help you. – CRD Jan 03 '14 at 22:13
1

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

codingFriend1
  • 6,487
  • 6
  • 45
  • 67