当我将新的视图控制器推送到 self.navigation 控制器时,应用程序崩溃了
我有一个 iOS 5 应用程序。 当我想将视图推送到导航控制器时,应用程序崩溃:(
这是我的 appDelegate 部分:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.navigationController=[[UINavigationController alloc] init];
StartViewController *startViewController=[[StartViewController alloc] init];
[self.navigationController pushViewController:startViewController animated:YES];
[self.navigationController setNavigationBarHidden:YES];
[[UIApplication sharedApplication] setStatusBarHidden:YES];
self.window.backgroundColor = [UIColor whiteColor];
self.window.rootViewController=self.navigationController;
[self.window makeKeyAndVisible];
return YES;
}
这是我推送新的视图控制器方法:
-(IBAction)startPressed:(id)sender
{
NSLog(@"startPressed: called");
//loading RootViewController (mainscreen view)
RootViewController *rootViewController=[[RootViewController alloc] init];
[self.navigationController pushViewController:rootViewController animated:YES];
}
应用程序在字符串处崩溃 [self.navigationController PushViewController:rootViewControllerAnimated:YES];< /code>
请帮我解决这个问题?
I have an iOS 5 application.
When I want to push view to my navigation controller, the application crashes :(
Here's my appDelegate part:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.navigationController=[[UINavigationController alloc] init];
StartViewController *startViewController=[[StartViewController alloc] init];
[self.navigationController pushViewController:startViewController animated:YES];
[self.navigationController setNavigationBarHidden:YES];
[[UIApplication sharedApplication] setStatusBarHidden:YES];
self.window.backgroundColor = [UIColor whiteColor];
self.window.rootViewController=self.navigationController;
[self.window makeKeyAndVisible];
return YES;
}
Here's my pushing new view controller method:
-(IBAction)startPressed:(id)sender
{
NSLog(@"startPressed: called");
//loading RootViewController (mainscreen view)
RootViewController *rootViewController=[[RootViewController alloc] init];
[self.navigationController pushViewController:rootViewController animated:YES];
}
Application crashed at a string [self.navigationController pushViewController:rootViewController animated:YES];
Help me, please. How to solve this problem?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
UINavigationController 需要 rootviewController:
将其更改
为
A UINavigationController wants a rootviewController:
Change the
to
解决了问题。我更改了 `[self.navigationController PushViewController:vcanimated:NO] 并调试给了我视图出口未设置的警告。所以我从界面生成器连接视图,问题就消失了。谢谢大家的帮助
Solved the problem. I changed `[self.navigationController pushViewController:vc animated:NO] and debug gave me the warning that the view outlet was not set. So I connected view from interface builder and the problem is gone. Thanks everybody for help
这是处理 UINavigationController 的一种奇怪的方式。在你的情况下,我想知道如果你更改
为
如果你的应用程序仍然崩溃,它是否有效,知道你是否重写
StartViewController
类的-loadView
方法会很有趣因为您没有使用– initWithNibName:bundle:
初始化它It's a strange way to deal with UINavigationController. In your case I would like to know if it works if you change
to
If your app still crashes, it would be interesting to know if you override
-loadView
method ofStartViewController
class as you don't initialize it with– initWithNibName:bundle:
我对pushViewController有同样的问题,但是当我尝试这样的事情时,
我得到相同的pointres,并且NSArray有1个项目。
问题出在其他地方。
如果有人可以帮助并添加一些适用于 PushViewController 的代码,因为我有正确的 NavigationController 但当我尝试推送 ViewControler 时出现错误
请有人为我解释这个问题。
i have same problem with pushViewController but when i try something like this
i get the same pointres, and the NSArray have 1 item.
The problem is somewhere else.
If someone can help and add some code that will work to pushViewController because i have the correct NavigationController but when i try to push the ViewControler i get error
Please could someone explained this issues for me.
我对pushViewController 也有一些问题。我检查了所有目标成员资格并发现我的 xib 文件未添加到必要的目标中。这对我有帮助。
我认为你还应该检查你的 xib 文件。
I also have some issue with pushViewController. I checked all target memberships and obtain that my xib file wasn't added to necessary target. This helps me.
I think you also should check your xib file.