0

我是 iOS 新手,我使用的是 Xcode 4.3.2,并且我使用 tabView 创建了一个项目,默认情况下它有两个视图控制器。我现在正在创建一个新的,

第三视图.h

#import <UIKit/UIKit.h>

@interface ThirdView : UIViewController

@end


#import "ThirdView.h"

@implementation ThirdView

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

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
        return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
    } else {
        return YES;
    }
}


@end

并在 appDelicate.m

viewController3 = [[ThirdView alloc] initWithNibName:@"ThirdView" bundle:nil];

并将 viewController3 添加到 tabBarController。

self.tabBarController.viewControllers = [NSArray arrayWithObjects:viewController1, viewController2, viewController3 ,nil];

问题是:当我在设备中执行代码时,我可以看到第三个选项卡,但是当我单击时,它崩溃了。我在哪里做错了?

4

1 回答 1

0

仔细检查 nib 文件中第三个视图控制器的类名。

于 2012-05-02T19:51:44.233 回答