gpt4 book ai didi

objective-c - EXC_BAD_ACCESS问题与发布声明

转载 作者:行者123 更新时间:2023-12-01 18:33:03 24 4
gpt4 key购买 nike

我不知道该语句有什么问题,因为我的代码与我从另一个项目复制的代码完全相同,但是当一切看起来不错时,它只会不断抛出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版本]之后,3不会出现。

我已经附上了项目。

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

提前致谢。

最佳答案

使用静态分析器

确实,使用产品菜单中的“分析”,它将在一秒钟之内找出问题所在。


[localControllersArray addObject:localNavigationController];

您使用之前释放了几行的数组。

编辑:是的,发布代码而不是上传项目是一种方法。猜猜我碰巧度过了美好的一天并下载了。

关于objective-c - EXC_BAD_ACCESS问题与发布声明,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6014727/

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