iosnibnulliboutlet

UIView in nib is nil on iPad, and not nil on iPhone


I have a weird problem with my app. I load a VC at runtime with a NIB named "LoginViewController." That NIB has a bunch of outlets to UIView objects that are placed in the NIB like so:

enter image description here

At runtime I dynamically place those UIView objects as headers in my table view. Each separate UIView in this case (except for the one with the UITableView in it, on the right) is set as an IBOutlet like so. Each has a different name of course:

@property (strong, nonatomic) IBOutlet UIView *connectionInProgressView;

Now, in my VC's viewDidLoad method I run through all four of these separate views and ensure they exist by writing to the log:

NSLog(@"connection in progress view: %@", self.connectionInProgressView);

My problem is this: self.connectionInProgressView is nil on iPad and not nil on iPhone. All the other views regardless of platform are NOT nil and are instantiated. I'm running this in the simulator on iOS 5.0, 5.1 and 6.1. I can recreate the issue on all iPad simulators. My app works just fine and loads the view with the spinner on iPhone, but on iPad it can't load that view because it's nil! Why!?

I have tried the following:

[EDIT 2]

Question: How is the VC loaded

I have a UINavigationController that is a property on my AppDelegate. That UINavigationController is alloc-init'd in applicationDidFinishLaunchingWithOptions to which I pass my VC as a root view controller. I instantiate the VC at this point.

// Create login/start up views
LoginViewController *loginViewController = [[LoginViewController alloc] initWithNibName:@"LoginViewController" bundle:nil];

self.loginViewNavigationController = [[UINavigationController alloc] initWithRootViewController:loginViewController];

if ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad)
    self.loginViewNavigationController.modalPresentationStyle = UIModalPresentationFormSheet;

Note that this is working on iPhone even though I'll present this UINavigationController later as a modal form sheet (not sure if that is contributing to my issue) on iPad.

Some time later in AppDelegate when a different delegate class throws an event I will present this UINavigationController, with my VC in it modally. I do that like this:

if (self.loginViewNavigationController != nil) {

    [self.window.rootViewController presentViewController:self.loginViewNavigationController animated:YES completion:nil];
}

I'm going bonkers trying to determine why this one particular view dragged onto my NIB and wired up the same as all the others is nil on an iPad and not nil on iPhone.

[EDIT 1] While searching for a duplicate question I failed to find this:

A few IBOutlets pointing to nil

I am not alone!

Any ideas?


Solution

  • As you are building an Universal app, are you sure you didn't create a separate NIB for iPhone and iPad (LoginViewController.xib and LoginViewController~ipad.xib typically)?

    Or maybe you thought you have only one XIB but at some point you had a dedicated XIB for iPad that got compiled into a NIB and even if you deleted the XIB file in your project, the compiled NIB dedicated for iPad is still in the build products.

    In any case, try to:

    If this does not work, some ideas to help you debug and identify if the issue is related to the iPad using a different XIB or not: