returned NO from -[NSWindow canBecomeKeyWindow]

There is a tips popup window in my program, I set it to close after 3 seconds, and the makeKeyAndOrderFront function is never called on it. However, the following error will appear during operation:

Warning: -[NSWindow makeKeyWindow] called on NSWindow 0x7fb... which returned NO from -[NSWindow canBecomeKeyWindow]

I'd like to know if there are any other function calls that would cause the above warning? Or how can I troubleshoot and remove this warning.

Replies

I had this problem and overrode -makeKeyWindow and set a breakpoint to see how I got there:

@interface AssistedTextFieldWindow : NSWindow
@end

@implementation AssistedTextFieldWindow

-(void) makeKeyWindow
{
    [super makeKeyWindow];    // break here
}

@end
(lldb) bt
* thread #1, queue = 'com.apple.main-thread', stop reason = breakpoint 38.1
    frame #0: 0x000000010491bb90 BRP Character`-[AssistedTextFieldWindow makeKeyWindow](self=0x0000000154e22270, _cmd="makeKeyWindow") at AssistedTextField.m:19:5
    frame #1: 0x00000001967aac4c AppKit`-[NSWindow _makeKeyRegardlessOfVisibility] + 56
    frame #2: 0x00000001967a332c AppKit`-[NSWindow makeKeyAndOrderFront:] + 24
  * frame #3: 0x000000010491c578 BRP Character`-[AssistedTextField didMakeFirstResponder:](self=0x0000000154f0e2f0, _cmd="didMakeFirstResponder:", obj=@"DidMakeFirstResponder") at AssistedTextField.m:132:29

Looking at AssistedTextField.m:132 I have:

windowController.window.isVisible = YES;

So that's how I got here. What to do about it? I have no idea.