How to remove view from window?
- by Wayfarer
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?