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:
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:
- Checking that my NIB's File's Owner points to the proper view
- That the
self.connectionInProgressView
doesn't point to any other IBOutlet - Checking that all the other sub views are hooked up the same way as the offending view. They are.
- Deleting
self.connectionInProgressView
and re-creating it after removing all its NIB connections. - Removing the activity indicator from the view and loading just a view with a
UILabel
inside. No luck, its not the activity indicator. - Checked for any code in the VC that might reference
self.connectionInProgressView
. There is none (other than it's nil statement inviewDidUnLoad
). - Checking the property attribute types on my AppDelegate properties of the
UINavigationController
andLoginViewController
. - Retaining a copy of
LoginViewController
on AppDelegate, though this seems wasteful and didn't make a difference in the outcome.
[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?