Problem
IBOutlet is released before I have the opportunity to use it.
What I want
I want to access the navigation controller from my application delegate so that I can reload the table view.
My setting
I have:
- A Main.xib, which is set as the main interface in the target settings
- IBOutlet for navigation controller as ivar for my application delegate
- This IBOutlet connects to the correct navigation controller in Main.xib
- App Delegate is created in xib but not set as File Owner
I am using ARC, Xcode 4.3.2 and iOS5.1
What i tried
- Change Deployment Goal
- Putting a breakpoint on dealloc for the navigation controller, application delegate - they are never called
- Reading everything I can find on ARC and IBOutlets - nothing contradicts what I do.
- Creating a new project with the minimum required classes - I see exactly the same problem
the code
KPAppDelegate.h
@interface KPAppDelegate : UIResponder <UIApplicationDelegate> { IBOutlet KPBrowseExpensesNavigationController *nc; } @property (strong) IBOutlet KPBrowseExpensesNavigationController *nc;
KPAppDelegate.m
@implementation KPAppDelegate @synthesize nc; -(void)setNc:(KPBrowseExpensesNavigationController *)nc_ { nc = nc_; // This gets called on view load and nc gets set. } ...snip... // This is called about 5 seconds after app startup -(void)objectLoader:(RKObjectLoader *)objectLoader didLoadObjects:(NSArray *)objects { // By the time we get here, nc is nil. UITableViewController *tvc = [[nc viewControllers] objectAtIndex:0]; [[tvc tableView] reloadData]; } @end
UPDATE
I have to do something really stupid here. Even an incredibly simple project still shows this problem. See the link below.
Download a simple test project that shows the problem.
source share