Document sheet not responding to keyboard events

2019-03-24 14:07发布

问题:

I think it's a first responder problem, but I'm not sure. I'm implementing an edit window for data in a table view. Very similar in concept to the UI for editing filter rules in Mail.app.

I have an editing window that I attach to my primary window with:

[NSApp beginSheet: criteriaEditPanel 
   modalForWindow: [self window] 
    modalDelegate: self 
   didEndSelector: @selector(criteriaEditDidEnd:returnCode:contextInfo:) 
      contextInfo: (void *)[criteriaList objectAtIndex: index]];

The panel displays properly, from the title bar of the main window. I can manipulate the pop-up controls on the panel with the mouse, but I can't edit the text fields and I can't tab between fields. Everything else works fine. Any ideas?

joe

回答1:

Solved. Believe it or not, you have to have the Title Bar enabled for the panel, even though it's never visible when displayed as a Sheet. When enabled it in IB, keyboard input started working.

@spudwaffle - none of the objects had Refuse First Responder checked.