Re: Swapping an NSView between NSWindows
Re: Swapping an NSView between NSWindows
- Subject: Re: Swapping an NSView between NSWindows
- From: Matt Neuburg <email@hidden>
- Date: Sun, 08 May 2005 15:46:13 -0700
On Fri, 6 May 2005 15:35:58 -0700, Michael Wood
<email@hidden> said:
>Hi, I have a document-based application with a main NSWindow
>(mainWindow). The mainWindow has an NSView (mainView) which was added
>using Interface Builder. While the application is running, I
>programatically create a new window and set its content view using
>setContentView:
>
>[newWindow setContentView:mainView];
>
>This has the desired effect of moving my view to the newWindow,
>without any delay. Transfering the view from one window to another in
>this way seems to wipe out the view in the original window.
>
>I would like to transfer the view back to the original window from
>the newWindow (the same way it was set up in Interface Builder). My
>problem is that I can't use "[mainWindow setContentView:mainView]"
>because it removes the entire content view from the original window
>which contain buttons that need to remain.
>
>Is there any way to swap an NSView between NSWindows by either:
>
> a) programatically sizing and positioning an NSView inside an
>NSWindow?
> b) reconstructing the NIB and replacing the NSView with my
>mainView?
> c) referencing my mainView in my newWindow so [newWindow
>setContentView:mainView]; doesn't kill the mainView from my mainWindow?
An NSView instance is a thing. Like most things, it can only be in one place
at a time. If an NSView is instantiated in a window, that same NSView cannot
be instantiated in a different window at the same time.
Now, in a situation similar to yours, I used an NSView that was not the
contentView of either window. It was a subview. I knew I couldn't show the
NSView in Window A and Window B at the same time. So first I showed Window
A, with the NSView in it - not as Window A's content view but as a subview
of the content view. When the user pressed the button saying "I want to see
Window B", I ripped the NSView out of Window A and shrank Window A in a
clean-looking way, so that the other stuff in Window A that the user still
needed to be able to get to was still present. Meanwhile I stuffed the
NSView into Window B and showed Window B. So now both Window A and Window B
were showing and the NSView was in Window B. When the user closed Window B,
I ripped out the NSView again and stuck it back into Window A. By this sort
of sleight of hand I was able to show the user the same info in two
different windows using the same NSView - just not at the same time. But the
user didn't care because he always had access to the info, in the window he
was primarily using.
Another approach might be to put the NSView into a nib of its own and just
open the nib twice, thus getting two identical NSViews. Now you can show
them in two different windows simultaneously. But I've never tried this. m.
--
matt neuburg, phd = email@hidden, <http://www.tidbits.com/matt/>
A fool + a tool + an autorelease pool = cool!
AppleScript: the Definitive Guide
<http://www.amazon.com/exec/obidos/ASIN/0596005571/somethingsbymatt>
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden