My app runs fine for a while in simulator, although after a few touches, it crash and burn.
Here is the code
-(IBAction)extraCrisp:(id)sender
{
myViewController *myView = [[myViewController alloc]
initWithNibName:@"myViewController"
bundle:nil];
// get the view that's currently showing
UIView *currentView = self.view;
// get the the underlying UIWindow, or the view containing the current view
UIView *theWindow = [currentView superview];
UIView *newView = myView.view;
// remove the current view and replace with myView1
[currentView removeFromSuperview];
[theWindow addSubview:newView];
// set up an animation for the transition between the views
CATransition *animation = [CATransition animation];
[animation setDuration:0.5];
[animation setType:kCATransitionPush];
[animation setSubtype:kCATransitionFromLeft];
[animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
[[theWindow layer] addAnimation:animation forKey:@"SwitchToView1"];
[myView release];
}
So, what am I doing wrong here? Any help would be highly praised. Thanx
Well Andy, your code certainly tells that you are a beginner..To implement your requirement there are much cleaner and safer methods available. For a multiview application, normally everyone uses either UINavigationController or UITabBarController. In your case UINavigationController is your friend and if you can spend one hour this tutorial will get you started..I recommend you learn to use those method other than continuing with the way you are doing now…and stop reading this answer..
OK now your code..This is the first part..
I rewrite your code this way..
now you are releasing myView after adding it to UIWindow. If you comment that line I think your crash will go..Normally UIViewController added to UIWindow are released in dealloc of application delegate file..
Now your animation..
Again..forget this code and read up UINavigationController..You are doing everything wrong there..