2012-03-16 2 views
0

: 나는 fellowing 코드를 언급하지 않는 경우아이폰 UITabBarController가 메모리 관리

내가 tabcontroller 다섯 UINavigationControllers를 추가하려는
FirstViewController *first = [[FirstViewController alloc]init]; 
    SecondViewController *second = [[SecondViewController alloc]init]; 
    ThirdViewController *third = [[ThirdViewController alloc]init]; 
    ForthViewController *forth = [[ForthViewController alloc]init]; 
    FifthViewController *fifth = [[FifthViewController alloc]init]; 

    first.tabBarItem = [[UITabBarItem alloc]initWithTitle:@"first" image:[UIImage imageNamed:@"FirstTab.png"] tag:0]; 
    second.tabBarItem = [[UITabBarItem alloc]initWithTitle:@"second" image:[UIImage imageNamed:@"SecondTab.png"] tag:1]; 
    third.tabBarItem = [[UITabBarItem alloc]initWithTitle:@"third" image:[UIImage imageNamed:@"ThirdTab.png"] tag:2]; 
    forth.tabBarItem = [[UITabBarItem alloc]initWithTitle:@"forth" image:[UIImage imageNamed:@"ForthTab.png"] tag:3]; 
    fifth.tabBarItem = [[UITabBarItem alloc]initWithTitle:@"fifth" image:[UIImage imageNamed:@"FifthTab.png"] tag:3]; 

UINavigationController *navigationFirst = [[UINavigationController alloc]initWithRootViewController:first]; 
UINavigationController *navigationSecond = [[UINavigationController alloc]initWithRootViewController:second]; 
UINavigationController *navigationThird = [[UINavigationController alloc]initWithRootViewController:third]; 
UINavigationController *navigationForth = [[UINavigationController alloc]initWithRootViewController:forth]; 
UINavigationController *navigationFifth = [[UINavigationController alloc]initWithRootViewController:fifth]; 

// [first release]; 
// [second release]; 
// [third release]; 
// [forth release]; 
// [first release]; 

NSMutableArray *array = [[NSMutableArray alloc]initWithObjects:navigationFirst,navigationSecond,navigationThird,navigationForth,navigationFifth, nil]; 

[navigationFirst release]; 
[navigationSecond release]; 
[navigationThird release]; 
[navigationForth release]; 
[navigationFifth release]; 

self.tabbarController = [[UITabBarController alloc]init]; 
self.tabbarController.view.frame = CGRectMake(0, 0, 320, 480); 
self.tabbarController.viewControllers = array; 
[array release]; 

, 그것은 충돌합니다

// [first release]; 
// [second release]; 
// [third release]; 
// [forth release]; 
// [first release]; 

하지만, 문제가 무엇인지 알고 싶습니다. thees 코드를 추가하는 것이 옳다고 생각합니다.

+0

내가 시도 할 코드를 줄 수 있습니까? – parag

답변

1

먼저 개체를 두 번 출시되는 내비게이션 컨트롤러를 해제해야합니다. 그게 당신의 코드가 부서지는 이유입니다. [첫 번째 릴리스]를 [다섯 번째 릴리스]로 바꿉니다.

0

당신은 말

UINavigationController *navigationFirst = [[UINavigationController alloc]initWithRootViewController:first]; 
UINavigationController *navigationSecond = [[UINavigationController alloc]initWithRootViewController:second]; 
UINavigationController *navigationThird = [[UINavigationController alloc]initWithRootViewController:third]; 
UINavigationController *navigationForth = [[UINavigationController alloc]initWithRootViewController:forth]; 
UINavigationController *navigationFifth = [[UINavigationController alloc]initWithRootViewController:fifth]; 

    [first release]; 
    [second release]; 
    [third release]; 
    [forth release]; 
    [first release]; 

NSMutableArray *array = [[NSMutableArray alloc]initWithObjects:navigationFirst,navigationSecond,navigationThird,navigationForth,navigationFifth, nil]; 

self.tabbarController = [[UITabBarController alloc]init]; 
self.tabbarController.view.frame = CGRectMake(0, 0, 320, 480); 
self.tabbarController.viewControllers = array; 

[navigationFirst release]; 
[navigationSecond release]; 
[navigationThird release]; 
[navigationForth release]; 
[navigationFifth release]; 

[array release]; 
+0

내가 코드를 시도했지만 작동하지 않습니다. 내 코드처럼 추락했습니다. – Tan

+0

중단 점을 시도 했습니까? – Shubhank