0

Hello I have a view which is shown when a button is pressed this works fine, if I open a second window the view works fine and I can go back the prior window and use the view as I have used removeFromSuperview.

My problem is however if I close the last opened window the view no longer works on the first window, however if I open a new window it works on the first window again.

How do I get the view to continue working when one of the windows have been closed?

Thanks for your help!

Here is the code I am using:

   -(IBAction) ShowView:(id) sender{
        [myView setHidden:FALSE];

        if ([myView isInFullScreenMode]){
            [myView exitFullScreenModeWithOptions:nil];

        }
        else{   
            [myView enterFullScreenMode:[[myView window] screen] withOptions:nil];

            for (NSView *view in [NSArray arrayWithArray:[myView subviews]]){
                [view removeFromSuperview];
                [myView addSubview:view];
            }
        }
    }
user1887683
  • 133
  • 2
  • 7
  • Try to rephrase and be more concise. – Mundi Dec 10 '12 at 21:36
  • What don't you understand in my question? – user1887683 Dec 10 '12 at 23:06
  • I do not understand what windows you are opening and closing, on which one the view is and what is working or not. Maybe use something like "window A", "window B" etc. Let us know in which class you accommodate and show the views. – Mundi Dec 11 '12 at 07:37
  • Ok I have Window A, I open the view and it works fine. I create a new window (Window B) I open the view and it shows fine. I go back to Window A and show the view and yet again it shows fine. I close Window B and then when trying to open the view again on Window A it doesn't show. Unless I open a new Window (let's call it Window B2) and then the view will work in Window A as well as the new Window B2. What I don't understand is why the view doesn't work on Window A when a later window is closed. – user1887683 Dec 11 '12 at 08:50

1 Answers1

0

You have not specified what it means that "the view does not work", but I assume that it does not appear when you expect it to.

If you are showing different views (i.e. copies of your view) associated with various windows, each view should be created and destroyed together with its window.

If you only want one view that is shown with or on various windows, you should create the view in a different class, e.g. in your application delegate. This class should manage the contents of the view independently from the classes that manage any window.

Mundi
  • 79,884
  • 17
  • 117
  • 140