2011-11-20 137 views
0

已經創建了一個小的兩個選項卡應用程序,然後再次劃分了另一個視圖控制器以創建第三個選項卡。應用程序編譯罰款沒有警告。但是當我點擊第三個選項卡時,應用程序崩潰,並在主文件中收到SIGABRT消息。當第三個選項卡點擊時,選項卡應用程序崩潰

你能幫我找出有什麼問題嗎?

TabBarFirstViewController.m

#import "TabBarFirstViewController.h" 

@implementation TabBarFirstViewController 

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil 
{ 
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; 
    if (self) { 
     self.title = NSLocalizedString(@"Screen One", @"Screen One"); 
     self.tabBarItem.image = [UIImage imageNamed:@"Screen One"]; 
    } 
    return self; 
} 

TabBarSecondViewController.m

#import "TabBarSecondViewController.h" 

@implementation TabBarSecondViewController 

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil 
{ 
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; 
    if (self) { 
     self.title = NSLocalizedString(@"Screen Two", @"Screen Two"); 
     self.tabBarItem.image = [UIImage imageNamed:@"Screen Two"]; 
    } 
    return self; 

}

ThirdViewController.m

#import "ThirdViewController.h" 

@implementation ThirdViewController 

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil 
{ 
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; 
    if (self) { 
     self.title = NSLocalizedString(@"Screen Three",@"Screen Three"); 
     self.tabBarItem.image = [UIImage imageNamed:@"Screen Three"]; 
    } 
    return self; 

}

TabBarAppDelegate.m

#import "TabBarAppDelegate.h" 

#import "TabBarFirstViewController.h" 

#import "TabBarSecondViewController.h" 

#import "ThirdViewController.h" 

@implementation TabBarAppDelegate 

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

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

的main.m與錯誤信息註釋掉

#import <UIKit/UIKit.h> 

#import "TabBarAppDelegate.h" 

int main(int argc, char *argv[]) 
{ 
    @autoreleasepool { 
     return UIApplicationMain(argc, argv, nil, NSStringFromClass([TabBarAppDelegate  class])); /* Thread 1: Program received signal "SIGABRT" (appears only when clicked on third tab) */ 
    } 
} 
+0

這些viewControllers不會釋放自己... –

回答

0

這行代碼是不正確的:

UIViewController *viewController3 = [[ThirdViewController alloc] initWithNibName:@"Third View Controller" bundle:nil]; 

我不知道你是什麼NIB的名字其實是,你必須檢查,但它不是「第三視圖控制器」。也許「ThirdViewController」?

+0

你是對的,這就是訣竅。拿出了空間,它的工作。謝謝! – pdenlinger

相關問題