我是iOS新手,我使用Xcode 4.3.2,我用tabView创建了一个项目,默认情况下它有两个视图控制器。我现在正在创建一个新的,
ThirdView.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];
问题是: 当我在设备中执行代码时,我可以看到第三个选项卡,但是当我点击它时,它会崩溃。 我在哪里做错了?
答案 0 :(得分:0)
仔细检查nib文件中第三个视图控制器的类名。