所以我有一个 NSViewController (MyVC) 设置如下:
//MyVC.h
...
@property (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]
现在,当我(通过MyVC *vc = [[MyVC alloc] init];
)加载这个 NSViewController 并将其加载到一个窗口中时,我可以适当地看到文本字段。但是,正如上面的粘贴(和几个 BAD_ACCESSes)所暗示的那样,vc.input
永远不会正确指向文本字段。
笔记:
- 该项目正在运行 ARC。
- 这不是简化或概括。我已经运行了这个确切的代码无济于事。
- 所有 IBOutlets 都绝对设置得当。