uitabbarcontroller 在启动时崩溃

发布于 2024-11-25 00:58:47 字数 1906 浏览 1 评论 0原文

我有一个 iPhone 应用程序,它有一个根视图,其中有一个按钮,该按钮可能会导致选项卡栏视图。当您单击根视图中的 UIbutton 时,它会触发执行以下代码的 IBAction 方法。由于某种原因,它在接近尾声时崩溃了。有什么想法吗?很高兴获得任何帮助...谢谢!

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) 

I have an iphone app that has a root view with a button that suppose to lead to a tab bar view. when you click on the UIbutton in the root view, it triggers an IBAction method that does the code below. From some reason it crashes towards the end. Any ideas? Would be happy to get any help...Thanks!!

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


 }

The app crashes here:

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

What am I doing wrong? Thanks!!

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) 

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

聆听风音 2024-12-02 00:58:47

如果没有任何错误信息,很难说。但是你试过了吗?

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

It's hard to say without having any error information. But have you tried

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

Also, are you sure that your nibs exist? You should use the bundle:

[[FirstView alloc] initWithNibName:@"FirstView" bundle:NSBundle.mainBundle];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文