この問題で私を助けてくれることを願っています。次のコードに問題があります。
-(IBAction)swapViews:(id)sender{
myappAppDelegate *delegate = (myappAppDelegate *) [[UIApplication sharedApplication] delegate];
ThirdViewController *thirdView = [[ThirdViewController alloc] initWithNibName:@"ThirdViewController" bundle:nil];
[delegate switchView:self.view toView:thirdView.view];
[thirdView release];
}
ご覧のとおり、ViewController を割り当ててから解放しました。問題は、ビューを ThirdViewController に変更してから前のビューに戻そうとすると、アプリがクラッシュすることです。これは、以前のビューに戻る方法です。
-(IBAction)goBack:(id)sender{
myappAppDelegate *delegate = (myappAppDelegate *) [[UIApplication sharedApplication] delegate];
FirstViewController *firstView = [[FirstViewController alloc] initWithNibName:@"FirstViewController" bundle:nil];
[delegate switchView2:self.view toView:firstView.view];
[firstView release];
}
ビューを解放するときも同じ問題が発生します。ビューを解放しなくてもアプリはクラッシュしませんが、メモリ リークが多く、ViewController が 15 個以上あることを考えると、アプリを長時間使用すると最終的にクラッシュします。
私が間違っていることは何ですか?ps:ビューのアニメーション/トランジションにデリゲートを使用しています。
ありがとう!
編集: switchView:toView: 以下のコード
-(void)switchView:(UIView *)view1 toView:(UIView *)view2 {
[UIView beginAnimations:@"Animation" context:nil];
[UIView setAnimationDuration:0.75];
[UIViewsetAnimationTransition:UIViewAnimationTransitionCurlUp forView:self.window cache:YES];
[view1 removeFromSuperview];
[window addSubview:view2];
[UIView commitAnimations];
}