2012-03-24 225 views
0

酒吧控制器, 我的项目名称是“DebtDevV1”,它在视图“AddDebtor”和“Debtor”之间切换。我基于“基于标签的应用程序”构建它。main.m中调试错误EXC_BAD_ACCESS

当我按下 “DebtorViewController”,它的main.m 错误消息停在下面的代码:

程序接收到的信号 “EXC_BAD_ACCESS”

,当我把我的光标上DebtDevV1AppDelegate,它显示"Out of Scope"

下面是main.m文件:

#import "DebtDevV1AppDelegate.h" 

int main(int argc, char *argv[]) 
{ 
    @autoreleasepool { 
     return UIApplicationMain(argc, argv, nil, NSStringFromClass([DebtDevV1AppDelegate class])); 
    } 
} 

下面是DebtDevV1AppDelegate.m

#import "DebtDevV1AppDelegate.h" 
#import "AddDebtorViewController.h" 
#import "DebtorViewController.h" 

@implementation DebtDevV1AppDelegate 

@synthesize window = _window; 
@synthesize tabBarController = _tabBarController; 

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{ 
    self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease]; 
    // Override point for customization after application launch. 
    UIViewController *viewController1 = [[[AddDebtorViewController alloc] initWithNibName:@"AddDebtorViewController" bundle:nil] autorelease]; 
    UIViewController *viewController2 = [[[DebtorViewController alloc] initWithNibName: 
    @"DebtorViewController" bundle:nil] autorelease]; 
    self.tabBarController = [[[UITabBarController alloc] init] autorelease]; 
    self.tabBarController.viewControllers = [NSArray arrayWithObjects:viewController1, viewController2, nil]; 
    self.window.rootViewController = self.tabBarController; 
    [self.window makeKeyAndVisible]; 
    return YES; 
} 

有谁遇到或对上述错误的想法? 谢谢!

+0

使用ARC并移除'autorelease'。 – 2012-03-25 12:01:37

+0

你的dealloc方法是什么样的? – syclonefx 2012-03-25 13:09:32

+0

对不起,我可以知道什么是ARC?你的意思是我需要删除所有[... autorelease]代码?或哪个autorelease删除? – 2012-03-28 15:06:24

回答

0

这听起来像我几个月前的相同问题。检查你的dealloc方法。确保[super dealloc]是您在dealloc方法中进行的最后一次调用。 EXC_BAD_ACCESS crash when switching back and forth between views

+0

我应该在2个视图中的.m文件中使用dealloc方法吗?目前我只有在AppDelegate.m文件中有dealloc方法 – 2012-03-28 15:07:24