call addsubview again causes slowdown

Posted by Tom on Stack Overflow See other posts from Stack Overflow or by Tom
Published on 2010-05-08T06:59:10Z Indexed on 2010/05/08 7:08 UTC
Read the original article Hit count: 289

hi guys,

i am writing a little music-game for the iphone. I am almost done, this is the only issue which keeps me from rolling it out. any help to solve this is much appreciated.

this is what i do: at my appDelegate I add my menu-view-screen to the window. the menu-view-screen acts as a container and controls which view gets presented to the user.

means, on the menu-view-screen I got 4 buttons (new game, options, faq, highscore). when the user clicks on a button something as this happens:

 if (self.gameViewController == nil)
 {
  GameViewController *viewController = [[GameViewController alloc] initWithNibName:@"GameViewController" bundle:nil];
  self.gameViewController = viewController;
  [viewController release];
 }
 [self.view addSubview:self.gameViewController.view];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleSwitchViewNotificationFromGameView:) name:@"SwitchView" object:gameViewController];

when the user returns to the menu, this piece of code gets executed:

 [[NSNotificationCenter defaultCenter] removeObserver:self];
 [self.gameViewController viewWillDisappear:YES];
 [self.gameViewController.view removeFromSuperview];

this works fine for all screens but not for the gamescreen(well this is the only one with heaps of user-interaction) means the responsiveness of the iphone(when playing tones) gets really slow. The performance is fine when I display the gameview for the first time. it starts getting slower as soon as I add it to the menu-views-container-subviews again (addsubview) (basically open up a new game) any ideas what causes(or to get around) this?

thanks heaps

Best regards Tom

© Stack Overflow or respective owner

Related posts about iphone

Related posts about subview