[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.
Related
Pretty simple idea here, I want to show all the NSWindows in an app. The idea being that there are two windows in the app, one his hidden the other is vissable. I want to show all the windows in the app and then hide one. I can hide the window I want to hide but I cant show the windows because I am unable to obtain a reference to it. is there anyway of getting a list of all the nswindows in the app then iterating through it and hiding them or something similar, I can use [NSApp windows] however trying to use
NSArray *windowArray = [NSApp windows];
[windowArray[0] makeKeyAndOrderFront:self];
[NSApp activateIgnoringOtherApps:YES];
does not work, nor does:
NSArray *windowArray = [NSApp windows];
NSWindow *tempWindow = windowArray[0];
[tempWindow makeKeyAndOrderFront:self];
[NSApp activateIgnoringOtherApps:YES];
any suggestions?
Well in hindsight I've been a bit stupid. I had two seep rate controller objects each running one window. One was hardly doing anything as the view inside it was being handled by a different object so I just removed that one and made the first controller object take care of both windows. Problem solved.
I have a window like this, having 3 subviews, each one of them has button. On click of those- I need to show sheet.
By using this code, sheet comes in centre of the window.
- (IBAction)closeSubWindow:(id)sender{
[NSApp endSheet:self.subWindow];
[self.subWindow orderOut:nil];
}
- (IBAction)showSubWindow:(id)sender {
[NSApp beginSheet:self.subWindow
modalForWindow:self.window
modalDelegate:self
didEndSelector:nil
contextInfo:nil];
}
Is there any option or way to show the sheet at specific co-ordinates?
EDIT:
My current implementation is by using NSPopover. Can I make this NSPopover to animate like sheet?
Take a look at the NSWindow delegate method -window:willPositionSheet:usingRect:
A sheet is per definition that what you see. So no, there is no way to place it at a different position. You could create an own implementation, but maybe it is better in your situation not to use a sheet but e.g. an NSPopover. This is availabe since OSX 10.7 and a great means to have a temporary view for displaying/entering values. By using the transient (or semi-transient) style the framework takes care for managing the display (automatically hiding the popover when no longer needed). Of course you can also have an OK button on it to commit changes.
The popover is also kinda modal, just like the sheet, so, functionally they are quite similar, but you have more freedom regarding its position.
I have one NSWindow (mainwindow) for my OSX NSApplicationDelegate. The NSWindow also holds several NSView's where the content is set using NSViewControllers. Currently I ran into a problem when I wanted a NSPanel, a sheet, to drop down from the top of one of my NSViews (not from the top of my app). I wanted to use the code:
[NSApp beginSheet:self.loginSheet.window
modalForWindow:self.view.window
modalDelegate:self
didEndSelector:nil
contextInfo:nil];
The loginSheet is a subclass of NSWindowController which loads the xib file using:
loginSheet = [[sheetWindowController alloc] initWithWindowNibName:#"loginSheet"];
However, I run this code from my NSViewController and my self.view.window is always nil. My NSView seems otherwise correctly initialized and works fine, but the drop down of the sheet does not work as my modalForwindow (self.view.window) is nil. If I use the code:
[NSApp beginSheet:self.loginSheet.window
modalForWindow:[[NSApplication sharedApplication] mainWindow]
modalDelegate:self
didEndSelector:nil
contextInfo:nil];
it works like a charm. But from all my searching to find an answer to my problem it seems that this working approach is a big no-no since it blocks the entire app from any response. I wanted my sheet to be linked to one of my NSViews' but I dont see how I can do this given that the app only have one NSWindow? Am I not doing something that makes my self.view.window stay nil? Is there a good way for me to find the parent window of custom views? If you have any suggestions for how to solve this problem or can give me a hint on what I am doing wrong that would be greatly appreciated.
Thanks! Cheers, Trond
You should have a look at the "Positioning Sheets" section of "Introduction to Sheets" docs. It explains how to make a sheet appear from somewhere other then under the window's title bar using window:willPositionSheet:usingRect:
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.
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.