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]; 

私が間違って何をしているのですか?ありがとう!!

CRASH LOG:

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)を使用して 'nil'であるかどうかを調べてみてください; ' –

+0

いいえ、それらはゼロではありません。ログ: – TommyG

+0

「NIB」の中にエラーがあるようです。 'view'プロパティをチェックしましたか?エラーはそれを明示的に言及します。 –

答えて

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にドラッグします –

関連する問題