How to remove view from window?

Posted by Wayfarer on Stack Overflow See other posts from Stack Overflow or by Wayfarer
Published on 2010-03-29T14:25:05Z Indexed on 2010/03/29 16:03 UTC
Read the original article Hit count: 381

Filed under:
|
|
|

I am using Cocos2D for my main framework. In some cases, I want Cocos2D to load a nib file and have that be the view:

window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
TargetPlayerViewController *myController = [[TargetPlayerViewController alloc]initWithNibName:@"TargetPlayerViewController" bundle:nil];
[window addSubview:[myController view]];
[window makeKeyAndVisible];

This works as expected, and shows the TargetPlayerViewController. Wonderful!

What I need to know is: once that view has been loaded, how can I have the view remove itself? I've tried a few different ways, but all of them result in the program crashing.

To test I have a button on the view set up which triggers this method:

- (IBAction)GTFOnow:(id)sender {
    NSLog(@"GFTO");
    window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    //[self.view removeFromSuperview];
    //[window makeKeyAndVisible];
}

In this method the view should remove itself from the view so I can go back to the Cocos2D. How do I do this?

© Stack Overflow or respective owner

Related posts about iphone

Related posts about cocos2d