0
votes

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];
}

GTFOnow is a method in TargetPlayerViewController. When it is called, the current subview (that was called in the Cocos2D code above) should be removed from the window.

1
"In this method the view should remove itself from the view". This is very confusing. I suppose you mean the view controller should remove the view from the window?Felixyz

1 Answers

0
votes

First of all, you shouldn't create a new window just because you want to remove a subview. Secondly, whatever else happens, this shouldn't cause the app to crash. In which class do you have the GTFOnowmethod? I suppose in the TargetPlayerViewController class?