ARC以外のプロジェクトがあります。だから私はそのメモリ管理を維持しています。タブバーとナビゲーションコントローラーがあります。タブバーを表示する前に起動時に、5秒の種類のものの起動ビデオを表示する必要があります。だから私は2つの質問があります
タブバーコントローラーをメインウィンドウにリークなしで接続する前に、ビューコントローラーを表示するための最良かつ簡単な方法。以下は私の現在の手法とコードですが、コードアナライザーはビデオコントローラーの潜在的なリークを示しています。
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
UIViewController *viewController = [[MyViewController alloc] initWithNibName:@"MyViewController" bundle:nil] ;
myNavigationController = [ [ UINavigationController alloc ] initWithRootViewController: viewController ];
[viewController release];
NSMutableArray *viewControllers;
viewControllers = [[NSMutableArray alloc] init];
[viewControllers addObject: myNavigationController]; //Tab 1
myNavigationController release];
// ADD Tab 2 //ADD Tab 3 //ADD Tab 4
self.tabBarController = [[[UITabBarController alloc] init] autorelease];
self.tabBarController.viewControllers = viewControllers;
[viewControllers release];
//Add video contoller before showing tabs
self.videoController = [[VideoPlayViewController alloc] initWithNibName:@"VideoPlayViewController" bundle:nil];
[self.window addSubview:videoController.view];
[self.window makeKeyAndVisible];
これが私のビデオプレーヤーコントローラーコードです
- (void)viewDidLoad
{
[super viewDidLoad];
MPMoviePlayerController *moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:@"some url"];
//------ init code in between and added observer to movie playback finish callback ------
[self.view addSubview:moviePlayer.view ]; //show potential leak here if i not release moviePlayer
//[moviePlayer release]; //if i release here controller show me black window with no video playing
}
- (void) moviePlayBackDidFinish:(NSNotification*)notification {
MPMoviePlayerController *player = [notification object];
[[NSNotificationCenter defaultCenter] removeObserver:self
name:MPMoviePlayerDidExitFullscreenNotification
object:nil];
[player stop];
[player.view removeFromSuperview];
[player release]; //show incorrect decrement of reference count of an object that is not owned at this point by caller
//Fire notification to add tab bar as root view controller
}
そして、ビデオが再生された後、私は私のappdelegateで通知を受け取り、その後
[videoController.view removeFromSuperview];
[self.videoController release];
self.videoController = nil;
self.window.rootViewController = self.tabBarController;
そして私のメインアプリはいつものようにdeallocを委任します
- (void)dealloc {
[_window release];
[_tabBarController release];
[super dealloc];
}
私は自分の問題を正しく説明したと思います。誰かがこれを行うためのより良い方法を持ってください。
ありがとう