创建了一个小的两个标签应用程序,然后将另一个视图控制器子类化以创建第三个标签。应用程序编译良好,没有警告。但是当我点击第三个选项卡时,应用程序崩溃了,我在主文件中收到了一条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 :(得分:0)
这行代码不正确:
UIViewController *viewController3 = [[ThirdViewController alloc] initWithNibName:@"Third View Controller" bundle:nil];
我不知道您的NIB名称究竟是什么,您必须检查,但它不是“第三视图控制器”。也许是“ThirdViewController”?