Приложение Tab вылетает при нажатии третьей вкладки - PullRequest
0 голосов
/ 20 ноября 2011

Создали небольшое приложение с двумя вкладками, а затем создали подкласс другого контроллера представления, чтобы создать третью вкладку.Приложение компилируется нормально без предупреждений.Но когда я нажимаю на третью вкладку, приложение вылетает, и я получаю сообщение 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) */
    }
}

1 Ответ

0 голосов
/ 20 ноября 2011

Эта строка кода неверна:

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

Я не знаю, как на самом деле называется ваше NIB, вам придется проверить, но это не «Контроллер третьего вида».Возможно "ThirdViewController"?

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...