【问题标题】:no methods on NSWindowController subclass are called没有调用 NSWindowController 子类的方法
【发布时间】: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


    【解决方案1】:

    您在 alloc/init 行中使用 NSWindowController 并希望它成为 HKLProfileWindowController 实例?为什么?

    您还需要将 File's Owner 自定义类设置为 HKLProfileWindowController,但是当您请求 NSWindowController 时,没有理由期望这足以获得 HKLProfileWindowController 实例。你得到的是一个NSWindowController,并且没有使用任何子类代码。

    如果您的代码来自您实施 HKLProfileWindowController 类之前的代码,我将删除此答案,但鉴于您在此处粘贴的内容,这就是您的断点不会被命中的原因。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-11-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多