I have two NSWindows
, both with an NSPanel
in them. I want to switch windows when a button is pressed. How can this be done? I don't need the old window any more so I just want to show the new one.
Asked
Active
Viewed 274 times
1

James Anderson
- 556
- 3
- 16
- 41
-
You want to change focus from one window to the other? Or perhaps animate the contents of one window into the other? Be more precise. – trojanfoe Nov 14 '12 at 08:21
-
"You want to change focus from one window to the other" - Yes, exactly that. Sorry :) – James Anderson Nov 14 '12 at 08:23
-
If you want to remove the “old” window from the screen, you can send it the `close` message or the `orderOut:` message. – rob mayoff Nov 14 '12 at 08:30
-
What do you mean, you have an NSPanel inside of each NSWindow? Are you adding them as child windows? If so, what for? And how is the child window (if that is what you're doing) relevant to the switching-windows problem? And why do you want to hide the former window and not simply show the new window, either by itself or as a sheet? Showing one window and hiding another is highly irregular in Mac apps. – Peter Hosey Nov 14 '12 at 09:31
1 Answers
0
To focus the second window, simply call:
[window2 makeKeyWindow];

trojanfoe
- 120,358
- 21
- 212
- 242
-
Hi, I'm doing this but nothing happens and the old window stays in place: http://pastie.org/5375952 – James Anderson Nov 14 '12 at 08:33
-
@PixelBitAppsLtd: You can't create a window with `init`—the resulting window will have no frame rectangle and thus be unusable. Use one of the initializers listed in the NSWindow documentation. – Peter Hosey Nov 14 '12 at 09:29
-
@PeterHosey I tried this, but still no luck - the window does not change at all: http://pastie.org/5376517 – James Anderson Nov 14 '12 at 11:21
-
OK, would this be easier; could I just create a nib with an NSPanel in it and add it as a 'subview' to the NSWindow? How can I do this? (this is my first Mac app - I'm used to iOS Development) :-) – James Anderson Nov 14 '12 at 11:28
-
@PixelBitAppsLtd: No; windows are not views in Cocoa. You could do a child window, but that's probably not actually what you want (then again, you haven't really said what you're trying to do). Most probably, you should just make a nib with a view in it and add that view as a subview. – Peter Hosey Nov 14 '12 at 18:37