Управление памятью iphone UITabBarController - PullRequest
0 голосов
/ 16 марта 2012

В моей функции - (void)viewDidLoad:

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];

Я намереваюсь добавить пять контроллеров UINavigationController в tabcontroller, если я не прокомментирую код поддержки, он вылетит:

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

но я хочу знать, в чем проблема, я думаю, что правильно добавить код.

Ответы [ 2 ]

1 голос
/ 16 марта 2012

вы выпускаете первый объект дважды. вот почему ваш код падает. заменить [первый выпуск] на [пятый выпуск]

0 голосов
/ 16 марта 2012

Вы должны выпустить навигационные контроллеры в конце

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];
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...