IBOutlets Not Setting in NSViewController
So I've got an NSViewController (MyVC) set up like so:
//MyVC.h
...
@开发者_如何学Goproperty (nonatomic, retain) IBOutlet NSTextField *input;
...
//MyVC.m
...
@synthesize input;
- (id)init
{
self = [super initWithNibName: @"MyVC" bundle: [NSBundle mainBundle]];
NSLog(@"%@", input); //prints (null) always
return self;
}
- (void)loadView
{
[super loadView];
NSLog(@"%@", input); //still (null)
}
...
//MyVC.xib
Custom View [Referencing Outlet: File's Owner.view]
Text Field [Referencing Outlet: File's Owner.input]
Now, when I load this NSViewController (by way of MyVC *vc = [[MyVC alloc] init];
) and load it into a window, I see the Text Field appropriately. However, as the above paste (and several BAD_ACCESSes) would suggest, vc.input
is never properly pointing to the Text Field.
Notes:
- This project is running ARC.
- This is not a simplification or generalization. I've run this exact code to no avail.
- All IBOutlets are definitely set up appropriately.
The error was a combination of things.
One of my revisions was missing the IBOutlet tag, and none of them were retaining references to the ViewController at runtime.
精彩评论