IBOutlets 未在 NSViewController 中设置
所以我有一个 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]
现在,当我加载这个 NSViewController (通过 MyVC *vc = [[MyVC alloc] init];
)并将其加载到在一个窗口中,我正确地看到了文本字段。但是,正如上面的粘贴(以及几个 BAD_ACCESS)所暗示的那样,vc.input
永远不会正确指向文本字段。
注意:
- 该项目正在运行 ARC。
- 这不是简化或概括。我已经运行了这个确切的代码但无济于事。
- 所有 IBOutlet 均已正确设置。
So I've got an NSViewController (MyVC) set up like so:
//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]
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这个错误是多种因素综合造成的。
我的一项修订缺少 IBOutlet 标记,并且没有一个修订在运行时保留对 ViewController 的引用。
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.