2012-03-24 38 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