【发布时间】:2015-07-15 19:56:15
【问题描述】:
我有一个基于单击 Tableview 中的一行创建的窗口,实例化如下:
HKLUserProfileController *userProfileController = [[HKLUserProfileController alloc] initWithNibName:@"HKLUserProfileController" bundle:nil];
_wc =[[NSWindowController alloc] initWithWindowNibName:@"HKLProfileWindowController"];
[_wc.window.contentView addSubview:userProfileController.view];
// other extraneous stuff here
[_wc showWindow:self];
if([_wc.window canBecomeKeyWindow]) {
[_wc.window makeMainWindow];
[NSApp activateIgnoringOtherApps:YES];
[self makeKeyAndOrderFront:self];
}
这可行,但我似乎无法让窗口成为主/关键/前窗口。我试过了:
...从我创建 WindowController 的这个地方,以及从 View 被添加到 Window 的 NSViewController 的 viewDidLoad/loadView 内部。没有骰子。 (这是我的最终目标,所以如果您发现我明显遗漏了什么,请指出)。
所以我意识到我应该尝试在 WindowController 本身的子类中执行此操作...所以我想将其放入 windowDidLoad 中,但没有结果。我设置了一些断点,并尝试了其他逻辑 init 方法,令我惊讶的是,NONE 根本没有触发。
@implementation HKLProfileWindowController
- (void)windowDidLoad {
[super windowDidLoad];
// breakpoint here
}
-(void)awakeFromNib {
// breakpoint here
}
- (id)init {
// breakpoint here
self = [super init];
if (self) {
// breakpoint here
}
return self;
}
@end
据我所知,我的 xib 已正确连接为我的文件所有者的插座/代表。这让我相信这是问题的根源,但对于我的生活,我无法弄清楚问题是什么......
谢谢...
编辑
我意识到 keyWindow 发生了什么 - 因为它来自 TableView 中的 shouldSelectRow,它正在成为 mouseDown 事件的关键,但第一个窗口 - 包含 TableView - 再次成为 mouseUp 事件的关键......太疯狂了!
将寻找解决方案,但在此处向 cmets 开放!
(仍然无法弄清楚为什么 init 方法没有触发......
【问题讨论】:
标签: objective-c cocoa nswindow nswindowcontroller