gpt4 book ai didi

iPhone UITabBarController 内存管理

转载 作者:行者123 更新时间:2023-11-29 04:45:23 24 4
gpt4 key购买 nike

在我的函数中- (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];

我打算在tabcontroller中添加五个UINavigationController,如果我不注释相关代码,它会崩溃:

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

但我想知道问题是什么,我认为添加这些代码是正确的。

最佳答案

您正在释放第一个对象两次。这就是你的代码崩溃的原因。将 [第一个版本] 替换为 [第五个版本]

关于iPhone UITabBarController 内存管理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9732354/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com