2011-05-16 18 views
1

私は別のプロジェクトからコピーしたのとまったく同じコードを持っているが、すべてがうまく見えるときにEXC_BAD_ACCESSを投げ続けるので、そのステートメントに何が問題なのか分かりません。誰でも問題を突き止めることができますか?私はこのエラーが数時間続いているので大いに感謝しています。同じコードは、悪いアクセスや白い画面が表示されるなど異なる結果を生み出しています。EXC_BAD_ACCESSリリース文での問題

コードフラグメント:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{ 

NSLog(@"0"); 
UINavigationController * localNavigationController; 

tabBarController = [[UITabBarController alloc] init]; 
NSMutableArray * localControllersArray = [[NSMutableArray alloc] initWithCapacity:4]; 

//ProductViewController 
ProductViewController * productViewController; 
productViewController = [[ProductViewController alloc] initWithTabBar]; 

localNavigationController = [[UINavigationController alloc] initWithRootViewController: productViewController]; 
[localControllersArray addObject:localNavigationController]; 
NSLog(@"1"); 
// memory statements 
[localNavigationController release]; 
[productViewController release]; 


//Search View Controller 
SearchViewController * searchViewController; 
searchViewController = [[SearchViewController alloc] initWithTabBar]; 
localNavigationController = [[UINavigationController alloc] initWithRootViewController: searchViewController]; 
[localControllersArray addObject:localNavigationController]; 

// memory statements 
[localControllersArray release]; 
[searchViewController release]; 
NSLog(@"2"); 
//Register View Controller 
RegisterViewController * registerViewController; 
registerViewController = [[RegisterViewController alloc] initWithTabBar]; 
localNavigationController = [[UINavigationController alloc] initWithRootViewController:registerViewController]; 

[localControllersArray addObject:localNavigationController]; 
NSLog(@"3"); 
//memory management 
[localControllersArray release]; 
[registerViewController release]; 

//About View Controller 
AboutViewController * aboutViewController; 
aboutViewController = [[AboutViewController alloc] initWithTabBar]; 
localNavigationController = [[UINavigationController alloc] initWithRootViewController: aboutViewController]; 
[localControllersArray addObject:localNavigationController]; 

//memory management 
[localNavigationController release]; 
[aboutViewController release]; 
NSLog(@"4"); 
// Override point for customization after application launch. 
tabBarController.viewControllers = localControllersArray; 


[window addSubview:tabBarController.view]; 
// Override point for customization after application launch. 
[self.window makeKeyAndVisible]; 
return YES; 

のNSLogが問題だった場所を確認することでした。 [localNavigationController release]の後に3は表示されません。

私はプロジェクトに添付しました。事前に

http://www.mediafire.com/?eauye5s361cyej0

感謝。

+0

コードフラグメントはどうですか? – Eimantas

+1

申し訳ありませんが、プロジェクト全体をダウンロードして解凍してから、エラーの原因を推測しません。質問にいくつかのコードを記入してください。 – JeremyP

答えて

2

は、製品メニューから「分析」を使用し、実際に静的アナライザ

を使用し、それは秒以内に問題をピンポイントであろう。

あなたは前にいくつかの行をリリースし、配列を使用

[localControllersArray addObject:localNavigationController]; 

編集:はい、プロジェクトをアップロードするのではなく、コードを投稿することをお勧めします。私はちょうど良い一日を持ってダウンロードされたと思う。ちょうどあなたのNSLog(@"3");文の後

[localControllersArray release]; 

2

エラーがです。

localControllersArrayは、NSLog(@"2")ステートメントの前に既にリリースされています。

解決策はNSLog(@"2")の前に[localControllersArray release];を削除することです。