【问题标题】:iPhone ModalViewController not navigating to next viewiPhone ModalViewController 未导航到下一个视图
【发布时间】:2012-08-17 14:17:54
【问题描述】:

我有一个从 App Delegate 显示的 ModalViewController。 ModalViewController 启动良好,并将执行各种操作,例如 [self dismissModalViewControllerAnimated:YES];正如预期的那样。

dismiss 有效,但我无法让 ModalViewController 导航/滑动到下一个视图。我的代码中没有收到任何错误或警告。

-(IBAction)signUpButtonTapped {
    // i need to get the control for main navigation controller
    HHHTabAppDelegate *appDelegate = (HHHTabAppDelegate *)[[UIApplication sharedApplication]delegate];
    [appDelegate.navigationController popToRootViewControllerAnimated:NO];
    // create object from app main view to push it
    SignUpViewController *signUpViewController = [[SignUpViewController alloc] initWithNibName:@"SignUpViewController" bundle:nil];
    [appDelegate.navigationController pushViewController:signUpViewController animated:YES];
}

【问题讨论】:

    标签: iphone uinavigationcontroller uitabbarcontroller modalviewcontroller


    【解决方案1】:

    基本上,当您第一次打开模态视图时,您需要提供UINavigationController 而不是SignupViewController。代码可能如下所示:

    ModalViewController *modalViewController = [[ModalViewController alloc] initWithNibName:@"ModalViewController" bundle:nil];
    UINavigationController *modalNavController = [[UINavigationController alloc] initWithRootViewController:modalViewController];
    
    [appDelegate.navigationController presentModalViewController:modalNavController animated:YES];
    

    您的问题是您将推送消息发送到 UINavigationController 的 nil 实例。

    【讨论】:

      【解决方案2】:

      对于弹出和推送视图控制器,您需要预先设置导航控制器。 Here 你可以找到关于如何在没有 xib 或故事板的情况下创建导航控制器的教程。

      【讨论】:

      • 现在查看。您是否需要将 navigationController 设置在与我发布的代码相同的 .m 文件中?还是我需要把它放在 SignUpViewController (被推送到的页面)中?
      • 但是如果你的第一个视图控制器是以模态方式呈现的,你应该在第一个上做
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多