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
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.
Related
I'm using a NSPanel with HUD style to display some information.
There's a button inside the HUD panel, when the user clicks the button, I'll open a new window by calling:
[anotherWindowController showWindow:self];
[anotherWindowController.window makeKeyAndOrderFront];
And I want the panel disappear when the window shows, so I set the delegate of the main window, and in the windowDidResignMain callback, I called [hudPanel orderOut:nil].
The HUD panel did disappear (I can see it), but right after it closed, it reopens.
I've checked all possible orderFront: code, and none of them get called. So my hands are really tied. Is this a system level behaviour? Can anyone guide me through this?
EDIT:
I forgot to mention that, the button resides in a NSPopover. So, basically, there's a NSButton in the HUD panel. When user clicks the button, a NSPopover will show up, inside which, there's the button to bring up the new window.
Big thanks!
I had the problem. The following solved it:
[NSApp endSheet:yourPanel];
[yourPanel orderOut:self];
Use
[hudPanel performClose:nil]
(in Swift I have to use self instead of nil). I had a problem using orderOut with a popover and it was solved by using the above method.
Please add [hudPanel close] after [hudPanel orderOut:nil]
swift: hudPanel.close()
from the apple docs:
If the window is the key or main window, the window object immediately behind it is made key or main in its place. Calling orderOut(_:) causes the window to be removed from the screen, but does not cause it to be released. See the close() method for information on when a window is released.
Sometimes the window reappears during window controller inner logic, I think. I have an issue when long pressing keyboard button kills window, but shot keyDown event only hides it on the split second. After using close all goes smoothly.
I am developing a cocoa application that has a main window and several panel windows.
I need to autosave some text on a NSTextField (which is on a panel window) when user leaves the textfield by clicking the main window etc. so far I have tried out by implementing resignFirstResponder on a NSTextField subclass,however if I click on another textfield on the same window "resignFirstResponder" gets triggered but if I just click on somewhere empty on my main window it does not get triggered. (NSTextField loses the blue focus though)
I need to capture this event the NSTextField loses the focus ring to save the uncommitted changes . Any pointers would be highly appreciated.
This text field is on NSTableCellView
use [[NSApp mainWindow] resignFirstResponder];
How about using the NStextfield's action sent on end editing
Then simply right-click-drag to an object (or FirstResponder) in your Xib file and connect it to a method. It should now run this method when you end the editing (deselect, Enter or Tab).
All keyboard events for my NSTableView are disabled. I can't use arrows or select a row with space bar.
The NSTAbleView belongs to a NSPanel, which is the current key Window, and the NSTableView is the first responder of the panel:
print (int) [self isKeyWindow] $1 = 1
po [self firstResponder] <NSTableView: 0xa7c6cc0>
If I remove the table from my panel (and also the other table) the ESC button works again. I guess something is wrong with the table event handling.
thanks
Your table view has lost its first responder status. Do you have any other controls in the window that are responding to key events? Try setting your window's intital first responder, making other controls refuse first responder, setting up your nextKeyView paths, or manually setting the table as the first responder by calling [window makeFirstResponder:tableView].
First responder issues can be a PITA, but if you read the documentation and go through your code with logging statements you can get an idea of where those key events are going.
[NSApp beginSheet] is used like so:
[NSApp beginSheet:[testSheetController window]
modalForWindow:[NSApp mainWindow]
modalDelegate:nil
didEndSelector:nil
contextInfo:nil];
Upon execution the sheet appears for a split second, although it is floating and not attached to the window like a sheet normally would, and then disappears. [NSApp mainWindow] is verified to not be nil. No exceptions are produced. Can anyone suggest what might be causing this behaviour?
I'm adding to an existing project and I've been trying to mimic the structure and the creation of other sheet controllers which are working with this window.
These appear to be two distinct problems: Your sheet probably disappears because it is being released to early. Make sure testSheetController is retained as long as the sheet is visible. The brief flickering in a detached state is likely caused by the Visible at launch property you can turn off when editing the NIB/XIB in Xcode/Interface Builder.
I have a NIB which contains two windows, one is the app's main window visible at launch and the other is a custom sheet (and therefore not visible at launch). When the sheet is required my controller calls:
[NSApp beginSheet: sheetWindow modalForWindow: mainWindow modalDelegate: self didEndSelector: #selector(didEndSheet:returnCode:contextInfo:) contextInfo: nil];
which displays the sheet window and starts a modal session, but the window has a standard Aqua title bar, is not 'connected' to the main window and can be moved around just like a regular window. Needless to say, this is not desirable :-). Why doesn't the sheet window "pop out" of the window it's run for, as sheets usually do when begun in this fashion?
I had wondered whether the fact that I was beginning the sheet inside the controller's -awakeFromNib might have an effect, so I moved the sheet to a button's action I could trigger later. This didn't change the behaviour. I haven't thought of anything else to try. I'm targeting the 10.5 SDK, using Xcode 3.1.
Edit: so it looks like I've created a modal dialog; sheets and app-modal dialogs are both started with the -beginSheet:modalForWindow:modalDelegate:didEndSelector:contextInfo: method. But how do I indicate that my window should be a sheet and not a modal dialog?
This happened to me a couple of days ago:
You forgot to set the window outlet of your window controller (File's owner of the Nib file).
As Indicated by Nathan, you may see that the -[NSWindowController window] method returns nil.
You must also uncheck the Visible at launch option of the sheet.
If mainWindow is nil then the sheet will be displayed as a window/dialog.