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

标签 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版本]之后,3不会出现。

我已经附上了项目。

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

提前致谢。

最佳答案

使用静态分析器

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


[localControllersArray addObject:localNavigationController];

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

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

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

相关文章:

ios - 在 SwiftUI 的列表行(TableviewCell)中单击按钮导航到详细 View

ios - 如何使用 Xcode9 在 Debug 区域中显示此 Log 消息?

iphone - 如何解决/处理委派EXC_BAD_ACCESS错误?对象C

iphone - UIImage 不是编译时常量,Xcode 4

ios - 使用 Parse 和 AWS Cognito

ios - 在 iOS 应用程序中调试 MIDI

xcode - NSNotification EXC_BAD_ACCESS

objective-c - UIProgressView : modify height for track line

ios - 有什么方法可以检查 iCloud Drive 是否打开?

objective-c - 如何用新的 viewController 替换当前的 viewController