2011-11-20 139 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

相关问题