【问题标题】:Using pushViewController: animated:使用 pushViewController: 动画:
【发布时间】:2011-08-10 08:57:47
【问题描述】:

我正在尝试将 pushViewController: animated: 与 UIViewController 一起使用。我将它放在带有 initWithRoot 的 UINavigationController 中,但它仍然无法正常工作。

这是我的代码?我做错了吗?

CloudappSettingsViewController *cloud = [[CloudappSettingsViewController alloc] initWithNibName:nil bundle:nil];
        UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:cloud];
        [self pushViewController:nav animated:YES];
        [cloud release];

当它到达[self pushViewController:nav animated:YES];时总是崩溃

有什么想法吗? 谢谢

【问题讨论】:

    标签: iphone uiviewcontroller uinavigationcontroller push


    【解决方案1】:

    如果这是在您的应用程序委托中,只需将 UINavigationController 作为子视图添加到您的应用程序窗口即可。如果您想将 UINavigationController 呈现为模态视图控制器,请执行以下操作:

    [self presentModalViewController:nav animated:YES];
    

    【讨论】:

    • 它不在我的 AppDelegate 中。它在我的 ViewController 中。我希望为设置实现推送和弹出动画。我有一个让它工作的想法。现在让我试一试。 编辑将 SettingsViewController 设置为 UINavigationController 也不起作用
    【解决方案2】:

    它肯定会崩溃,因为您将 nib 设置为 nil。

    CloudappSettingsViewController *cloud = [[CloudappSettingsViewController alloc] initWithNibName:@"NibName goes here" bundle:nil];
    

    创建一个 nib 并将其分配给您的视图控制器。

    【讨论】:

    • 我今天早上早些时候确实尝试过。甚至可以在 UIViewController 上使用 pushViewController 和 popViewController 吗?
    • 是的,这绝对是可能的。在他们的视图控制器中,您总是可以像这样进行推送和弹出:[self.navigationController pushViewController:newViewController animated:YES];或为弹出做类似的事情。我刚刚在您的代码中注意到您只调用 SELF 进行推送,我猜这会导致崩溃。
    【解决方案3】:

    “self”是 UINavigationController 吗?

    您似乎正在尝试推动导航控制器,但这是向后的。您应该展示导航控制器并向其推送其他视图。

    因此,您所在的 UIView 应该已经在导航控制器中,然后您会将云推送到其中。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多