0

I am using presentModalViewController to try and display a UIView on top of some other views. I call presentModalViewController from controller1. I am trying to display views from controller2.

From controller1 I call controller2 as follows:

- (void) someButtonPressed: (id)sender
{
    MyController* controller2 = [ [ MyController alloc ] initWithNibName:nil bundle:nil ];

    [self presentModalViewController:controller2 animated:YES];
    //[self presentViewController:controller2 animated:NO completion:nil ];
}

In controller2 I then do this:

- (void)viewDidLoad
{
    [super viewDidLoad];
    if (YES){

        UIWindow* keyWindow = [[UIApplication sharedApplication] keyWindow];
        UIView* master = (UIView*)[keyWindow viewWithTag:100]; // Master is the entire app, but always oriented so top left corner is 0,0.

        UIView* newView = [ [ UIView alloc ] initWithFrame:CGRectMake(100, 100, 400, 400) ];

        [self setView:newView ];

        self.view.backgroundColor = [ UIColor clearColor ];
    }

}

The problem is that none of the content from the first controller shows through. I want the previous views to remain visible. Is there any way to make the views from the second controller clear of invisible? The reason I want to do this is because I want the second controller/view to display a transparent layer that will catch all touch events without them getting through to the views managed by controller1.

Thanks very much.

whatdoesitallmean
  • 1,586
  • 3
  • 18
  • 40

1 Answers1

0

Add the view as a sub view, that will work:

- (void) someButtonPressed: (id)sender
{
    MyController* controller2 = [ [ MyController alloc ] initWithNibName:nil bundle:nil ];

    [[self view] addSubview:[controller2 view]];
    // [controller2 release] if you aren't using ARC

    //[self presentModalViewController:controller2 animated:YES];
    //[self presentViewController:controller2 animated:NO completion:nil ];
}

If you are using viewDidAppear in controller2, place this line after the addSubView line:

[controller2 viewDidAppear:NO]

Same goes for other viewDid methods ;)

Rick van der Linde
  • 2,581
  • 1
  • 20
  • 22