Show all NSWindows - objective-c

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.

Related

Howto identify modalForWindow using NSViewController

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:

Re-show my main Cocoa application Window

Ok, as simple and silly as that may seem, this is my scenario :
The application window (there is just ONE main window) is minimized
The user clicks something on the dock menu
We want to bring that main window back
Simple?
Not quite.
I've tried accessing my main window via :
[[NSApplication sharedApplication] mainWindow]
[[NSApplication sharedApplication] windows]
and then sending a makeKeyAndOrderFront: message but it's simply NOT showing up.
I've even tried showing all windows (yep, it still sees as "windows" one-or-two (hidden) sheets I'm using...), but still nothing.
Could you suggest a way, I could finally show that window, WITHOUT having to set an outlet anywhere?
I don't know; I'm probably too tired to notice, but this thing is almost nerve-wrecking...
You can un-minimize a window like so:
if([aWindow isMiniaturized])
{
[aWindow deminiaturize:self];
}
However, the problem is that the window will lose main status when it is minimized, so you'll need some other way of identifying the window.
Why can't you just use an outlet?
You can make the app un-minimize all of its minimized windows like so:
for(NSWindow* win in [NSApp windows])
{
if([win isMiniaturized])
{
[win deminiaturize:self];
}
}
When the app launches, you could store a reference to the main window and register for the NSWindowDidMiniaturizeNotification. That will tell you when the main window minimizes, which might also help you.

NSApp beginSheet creates a sheet very briefly then disappears

[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.

what am I doing wrong in attempt to popup a web view and then allow user to go back

my app has tabBarController with 3 views and in one of them I want to popup a web browser with the ability to return back to the application. To do that I am using UINavigationController.
In myAppDelegate.h I have defined the property UINavigationController *nav and in myAppDelegate.m I have #synthesize nav.
In the class where the webPopup function resides upon pressing the button my code comes to this function.
- (IBAction)showWeb:(id)sender {
myAppDelegate *app=[[UINavigationController alloc] initWIthRootViewController:self];
// because I want to return back to the same view
webController *web = [[webController alloc] initWithStyle:UITableViewStypeGrouped];
[app.nav pushViewController:web animated:YES];
app.nav.view.frame = CGRect(,0,320,430);
[self.view.window addSUbview:app.nav.view];
}
The web popup occurs but it is moved vertically, when I press "back button" my former view appears as well and it is also shifted vertically from what it was before.
After going back and forth few times the thing hangs.
Questions:
1. what can cause the shift?
2. how to avoid when I go "back" to see the title(test from the "back"button, I think this might cause a shift when I go back.
3. how to find out why it hangs after few attempt?
Thanks.
Victor
The line:
myAppDelegate *app=[[UINavigationController alloc] initWIthRootViewController:self];
makes no sense to me. Surely your compiler is warning you about that? What is "myAppDelegate" defined as? Classes should have a capital letter at the front, by the way.
Also, the line
[self.view.window addSUbview:app.nav.view];
is highly suspect, because the UIWindow for your application should have only one child UIView. You shouldn't just add more views willy nilly and expect things to work. It is possible to change the child UIView by removing the old one and adding a new one, but you don't seem to be doing that. Having more than one child UIView of UIWindow gets you into trouble very quickly -- for example, device orientation changing can break.
I'm not exactly clear as to why the app delegate (or the window for that matter) needs to be messed with at all to do what you are trying to do. Sounds like you should just be using standard Nav View Controllers and Web Views.
Also, you are alloc init'ing w/o any memory management.

Is it possible to bring window to front without taking focus?

I am working on an application for my personal usage that will remind me of stuff at regular intervals and/or will require text entry. Hence this popup window has an NSTextField.
If the window pop's up when I am in the middle of typing, my typing transfers to the popup window which is very annoying! Is there any way to stop this, currently I am using:
[NSApp activateIgnoringOtherApps:YES];
[hudWindow makeKeyAndOrderFront:nil];
I have also tried:
[NSApp activateIgnoringOtherApps:YES];
[hudWindow orderFrontRegardless];
Is there any other way to do it?
[hudWindow orderFront: nil];
Moves the window to the front of its level in the screen list, without changing either the key window or the main window.
Did you try using setLevel:? Setting it to one of the higher levels should do the trick.
like
[hudWindow
setLevel:NSFloatingWindowLevel];