EXC_BAD_ACCESS发行声明问题

时间:2011-05-16 08:21:26

标签: objective-c ios 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

提前致谢。

2 个答案:

答案 0 :(得分:2)

使用静态分析器

实际上,请使用产品菜单中的“分析”,它会在一秒钟内找出问题所在。

[localControllersArray addObject:localNavigationController];

你使用之前发布过一些行的数组。

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

答案 1 :(得分:2)

错误在于:

[localControllersArray release];

在你的NSLog(@"3");陈述之后。

localControllersArray已在NSLog(@"2")声明之前发布。

解决方案是在[localControllersArray release];语句之前删除NSLog(@"2")