当我将新的视图控制器推送到 self.navigation 控制器时,应用程序崩溃了

发布于 2024-12-24 01:34:15 字数 1382 浏览 7 评论 0原文

我有一个 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 技术交流群。

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

发布评论

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

评论(5

情栀口红 2024-12-31 01:34:15

UINavigationController 需要 rootviewController:

StartViewController *startViewController=[[StartViewController alloc] init];
self.navigationController=[[UINavigationController alloc] initWithRootViewControllr:startViewController];

[self.navigationController setNavigationBarHidden:YES];
[[UIApplication sharedApplication] setStatusBarHidden:YES];

将其更改

@autoreleasepool { 
     return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); 
}

NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
int retVal = UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); 
[pool release];

return retVal;

A UINavigationController wants a rootviewController:

StartViewController *startViewController=[[StartViewController alloc] init];
self.navigationController=[[UINavigationController alloc] initWithRootViewControllr:startViewController];

[self.navigationController setNavigationBarHidden:YES];
[[UIApplication sharedApplication] setStatusBarHidden:YES];

Change the

@autoreleasepool { 
     return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); 
}

to

NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
int retVal = UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); 
[pool release];

return retVal;

仅冇旳回忆 2024-12-31 01:34:15

解决了问题。我更改了 `[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

依 靠 2024-12-31 01:34:15

这是处理 UINavigationController 的一种奇怪的方式。在你的情况下,我想知道如果你更改

self.navigationController=[[UINavigationController alloc] init];

StartViewController *startViewController=[[StartViewController alloc] init];
[self.navigationController pushViewController:startViewController animated:YES];

StartViewController *startViewController=[[StartViewController alloc] init];
self.navigationController=[[UINavigationController alloc] initWithRootViewController:startViewController];

如果你的应用程序仍然崩溃,它是否有效,知道你是否重写 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

self.navigationController=[[UINavigationController alloc] init];

StartViewController *startViewController=[[StartViewController alloc] init];
[self.navigationController pushViewController:startViewController animated:YES];

to

StartViewController *startViewController=[[StartViewController alloc] init];
self.navigationController=[[UINavigationController alloc] initWithRootViewController:startViewController];

If your app still crashes, it would be interesting to know if you override -loadView method of StartViewController class as you don't initialize it with – initWithNibName:bundle:

三寸金莲 2024-12-31 01:34:15

我对pushViewController有同样的问题,但是当我尝试这样的事情时,

UINavigationController *rootViewController = (UINavigationController *)[[[UIApplication sharedApplication] keyWindow] rootViewController];
NSLog(@"NavControler:%@, %@", self.navigationController, rootViewController);

我得到相同的pointres,并且NSArray有1个项目。
问题出在其他地方。

如果有人可以帮助并添加一些适用于 PushViewController 的代码,因为我有正确的 NavigationController 但当我尝试推送 ViewControler 时出现错误

  ViewController* NextView = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];
UINavigationController *rootViewController = (UINavigationController *)[[[UIApplication sharedApplication] keyWindow] rootViewController];
[rootViewController pushViewController:NextView animated:YES];

请有人为我解释这个问题。

i have same problem with pushViewController but when i try something like this

UINavigationController *rootViewController = (UINavigationController *)[[[UIApplication sharedApplication] keyWindow] rootViewController];
NSLog(@"NavControler:%@, %@", self.navigationController, rootViewController);

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

  ViewController* NextView = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];
UINavigationController *rootViewController = (UINavigationController *)[[[UIApplication sharedApplication] keyWindow] rootViewController];
[rootViewController pushViewController:NextView animated:YES];

Please could someone explained this issues for me.

你曾走过我的故事 2024-12-31 01:34:15

我对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.

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