0

我有一个iPhone应用程序,它具有一个根视图,并带有一个按钮,该按钮可导致标签栏视图。当你在根视图中点击UIbutton时,它会触发一个执行下面代码的IBAction方法。从某种原因,它崩溃到最后。有任何想法吗?会很高兴得到任何帮助...谢谢!uitabbarcontroller在启动时崩溃

rootview.h

@interface RootView : UIViewController 

@property (strong, nonatomic) UIWindow *window; 

@property (strong, nonatomic) UITabBarController *tabBarController; 

@end 

rootview.m

-(IBAction)GoToTabBarView:(id)sender { 

self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; 
UIViewController *viewController1 = [[FirstView alloc] initWithNibName:@"FirstView" bundle:nil]; 
UIViewController *viewController2 = [[SecondView alloc] initWithNibName:@"SecondView" bundle:nil]; 
self.tabBarController = [[UITabBarController alloc] init]; 
self.tabBarController.viewControllers = [NSArray arrayWithObjects:viewController1, viewController2, nil]; 
self.window.rootViewController = self.tabBarController; 
[self.window makeKeyAndVisible]; 


} 

应用崩溃的位置:

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

我在做什么错?谢谢!!

崩溃日志:

2011-07-20 11:45:37.359 MyTabProject[17929:207] <FirstView: 0x6836070> <SecondView: 0x683c770> 
2011-07-20 11:45:37.410 MyTabProject[17929:207] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '-[UIViewController _loadViewFromNibNamed:bundle:] loaded the "FirstView" nib but the view outlet was not set.' 
*** First throw call stack: 
(0xf8c600 0x112452e 0xf31f59 0xf31ec9 0xdbe80 0xdc35d 0xdc57f 0xf6ec5 0xf6d13 0xf5438 0xf5264 0xf4f11 0xf42c6 0x4c93 0xf8dd78 0x1acc5 0x1ac5a 0xbfbd4 0xc009d 0xbee8c 0x3ff13 0x4022d 0x26990 0x1a1a7 0x136b886 0xf5bd11 0xebdc9b 0xebc4b1 0xebb93c 0xebb868 0x1369fef 0x136a0b4 0x180c4 0x2a99 0x2a05) 
terminate called throwing an exception(gdb) 
+0

是否有崩溃记录?尝试使用NSLog(@“%@%@”,viewController1,viewController2);' –

+0

记录要添加到数组中的值是否为'nil',否则它们不是零。日志: – TommyG

+0

似乎是'NIB'中的错误。你有没有检查他们的“视图”属性?错误明确提到。 –

回答

1

很难,而无需任何错误信息的话。但你有没有试过

NSMutableArray *listOfViewControllers = [[NSMutableArray alloc] init]; 
UIViewController *vc; 

vc = [[FirstView alloc] initWithNibName:@"FirstView" bundle:nil]; 
[listOfViewControllers addObject:vc]; 
[vc release]; 
vc = [[SecondView alloc] initWithNibName:@"SecondView" bundle:nil]; 
[listOfViewControllers addObject:vc]; 
[vc release]; 

[self.tabBarController.viewControllers setViewControllers:listOfViewControllers]; 

另外,你确定你的笔尖存在吗?您应该使用该软件包:

[[FirstView alloc] initWithNibName:@"FirstView" bundle:NSBundle.mainBundle]; 
+0

+1查看上面更新的日志。您建议的修复程序没有帮助,但是谢谢:) – TommyG

+0

因此,您必须连接界面构建器中的视图。您可以通过按住Ctrl键并单击文件所有者来完成此操作,然后将视图拖到FirstView –