开发者

How to remove view from window?

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]initWit开发者_如何学编程hNibName:@"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.


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?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜