UINavigationController - 应用程序尝试将零视图控制器推送到目标上,我错过了什么?

发布于 2024-12-19 22:35:09 字数 1710 浏览 3 评论 0原文

我在让导航控制器正常运行时遇到问题!如果我单击 RootViewController 处的表格单元格,它似乎不是下一个 ViewController。

读取错误消息

“应用程序试图将零视图控制器推送到目标上 .”

所以我猜测,我分配了一些错误的东西,我可能错过了我所关注的书中的一些重要内容。

所以问题出现在我的 RootViewController.m 中:

    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{

    UINavigationController *navigationController= [[UINavigationController alloc]init];

    switch ([indexPath row]) {

        case 0:
            [navigationController pushViewController:kundeViewCon animated:YES];
            break;

        case 1:
            [navigationController pushViewController:kalenderViewCon animated:YES];
            break;

        case 2:
            [navigationController pushViewController:wunschViewCon animated:YES];
            break;
    } 
}

在我的 AppDelegate.m 中,我正在执行以下操作来将 RootViewController 设置为 NavigationController:

 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    // Override point for customization after application launch.

// Navigation Controller

    RootViewController *rootViewController = [[RootViewController alloc]init];

    navigationController = [[UINavigationController alloc]initWithRootViewController:rootViewController];

    self.window.backgroundColor = [UIColor whiteColor];

    [self.window addSubview:navigationController.view];
    [self.window makeKeyAndVisible];
    return YES;
}

因此,当我单击单元格时,我得到了我想要推送的所有其他 ViewController。我只是看不到我的错或我错过了什么!?

也许有人可以帮助我并给我提示!那太好了!

I am having problems to get my Navigation Controller to run properly! If I click in the cell of the table at the RootViewController, it appears not the next ViewController.

Error message reads

“Application tried to push a nil view controller on target
.”

So I alloc something wrong, was my guessing, I probably missing something important from the book I follow.

So the problem appears here in my RootViewController.m:

    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{

    UINavigationController *navigationController= [[UINavigationController alloc]init];

    switch ([indexPath row]) {

        case 0:
            [navigationController pushViewController:kundeViewCon animated:YES];
            break;

        case 1:
            [navigationController pushViewController:kalenderViewCon animated:YES];
            break;

        case 2:
            [navigationController pushViewController:wunschViewCon animated:YES];
            break;
    } 
}

In my AppDelegate.m I am doing the following things to set a RootViewController as the NavigationController:

 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    // Override point for customization after application launch.

// Navigation Controller

    RootViewController *rootViewController = [[RootViewController alloc]init];

    navigationController = [[UINavigationController alloc]initWithRootViewController:rootViewController];

    self.window.backgroundColor = [UIColor whiteColor];

    [self.window addSubview:navigationController.view];
    [self.window makeKeyAndVisible];
    return YES;
}

So I got all my other ViewControllers that I want to push, when I click in the Cell. I just can not see my fault or what I am missing!?

Maybe someone can help me and give me a hint! That would be great!

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

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

发布评论

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

评论(3

再可℃爱ぅ一点好了 2024-12-26 22:35:09

RootViewController 已经有了它的导航控制器 - 您在应用程序委托中创建了它。选择单元格时创建新的导航控制器没有意义。它可能看起来应该更像这样:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    switch ([indexPath row]) {
        case 0:
            [self.navigationController pushViewController:kundeViewCon animated:YES];
            break;
        case 1:
            [self.navigationController pushViewController:kalenderViewCon animated:YES];
            break;
        case 2:
            [self.navigationController pushViewController:wunschViewCon animated:YES];
            break;
    }
}

另外,只需确保当您调用 -pushViewController:animated: 视图控制器(即 kundleViewConkalenderViewCon > & wunschViewCon) 不为零。它们看起来像实例变量或属性 - 只需确保您在代码的早期分配/初始化它们,例如在 -viewDidLoad 中。

RootViewController already has its navigation controller - you created it in the app delegate. Creating a new navigation controller when you select a cell doesn't make sense. It should probably look more like this:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    switch ([indexPath row]) {
        case 0:
            [self.navigationController pushViewController:kundeViewCon animated:YES];
            break;
        case 1:
            [self.navigationController pushViewController:kalenderViewCon animated:YES];
            break;
        case 2:
            [self.navigationController pushViewController:wunschViewCon animated:YES];
            break;
    }
}

Also, just make sure that when you call -pushViewController:animated: the view controller (i.e. kundleViewCon, kalenderViewCon & wunschViewCon) are non-nil. They look like instance variables or properies - just make sure you are alloc/initing them earlier in your code, like in -viewDidLoad.

野生奥特曼 2024-12-26 22:35:09

您不必创建新的 UINavigationController。您需要从当前窗口获取控制器。

[self.navigationController pushViewController:yourController animated:YES];

其中 yourController 是实例化的 UIViewController 之一(kundeViewCon、kalenderViewCon 或 wunschViewCon)

You don't have to create a new UINavigationController. You need to get you controller from the current window.

[self.navigationController pushViewController:yourController animated:YES];

where yourController is one of your instantiated UIViewController (kundeViewCon, kalenderViewCon or wunschViewCon)

ぶ宁プ宁ぶ 2024-12-26 22:35:09

对于 Google 员工:

如果您没有将 ViewController 连接到以下位置,也可能会发生这种情况:

“<您的项目>应用程序委托”

如果您不这样做,那么您的控制器将不会被初始化。

您还需要将ViewController的类重命名为相应的.h / .m文件:

打开xib文件->选择你的ViewController ->转到“身份检查器”->输入
文本字段“Class”相应 .h/.m 文件的名称。

将您的 ViewController 连接到应用程序
通过右键单击并从 ...AppDelegate 拖动到您的 ViewController
在此处输入图像描述
释放后点击相应条目:
在此处输入图像描述

For Googlers:

This may also happen if you did not connect your ViewController to the:

"<Your Project> App Delegate"

If you don't do it then your controller des not get initialized.

You also need to rename the class of the ViewController to the corresponding .h / .m file:

Open the xib file -> select your ViewController -> go to the "Identity Inspector" -> Type in the
Textfield "Class" the name of your corresponding .h/.m files.

Connect your ViewController to the App
By right click and drag from the ...AppDelegate to your ViewController
enter image description here
After releasing click on the corresponding entry:
enter image description here

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