【问题标题】:Push & Pop Problems Programmatically Created UINavigationController以编程方式创建的 UINavigationController 推送和弹出问题
【发布时间】:2013-11-27 16:44:50
【问题描述】:

我有一个视图控制器(MailServicesController),我以模态方式呈现。我正在尝试向此 MailServicesController 添加一个 UINavigationController(以编程方式),这将允许我推送和弹出另一个视图控制器(LoginController)。我已经实现了代码来做到这一点,但有两个具体问题:

  1. 导航控制器将 loginViewController 推送到堆栈顶部,但即使我在 push 方法中将动画 BOOL 设置为 YES,也不会对此转换进行动画处理。

  2. 在 loginViewController 中,当我尝试使用 popViewControllerAnimated 时,没有任何反应(我自己制作了弹出按钮,我没有使用导航控制器的导航栏)。

这是我用来在 MailServices 模式视图控制器中创建导航控制器的代码:

self.navigationController = [[UINavigationController alloc]init];
[self.navigationController willMoveToParentViewController:self];
self.navigationController.view.frame = self.view.frame;
[self.view addSubview:self.navigationController.view];
[self addChildViewController:self.navigationController];
[self.navigationController didMoveToParentViewController:self];
[self.navigationController pushViewController:LoginController animated:YES];
//pushes login controller but with no animation

然后在 LoginController 中,我尝试将 LoginController 从顶部弹出以显示我从中推送的控制器:

- (void)dismissView //called by a button in my custom toolbar
{

  UINavigationController *navigationController = (UINavigationController   
  *)self.parentViewController; //this is the navigationController I created
  [navigationController popViewControllerAnimated:YES]; //is called but does nothing
}

我不确定我做错了什么,谁能看到我的错误?

【问题讨论】:

  • 你在哪里初始化 UINavigation 控制器
  • 我只在上面的代码中初始化它
  • 您希望在整个应用程序中导航或单独导航这两个类

标签: ios objective-c uiviewcontroller uinavigationcontroller


【解决方案1】:

当以模态方式向 MailServicesController 呈现时,这样做

MailServicesController *vc = [[MailServicesController alloc]init];
UINavigationController *navController = [[UINavigationController alloc]initWithRootViewController:vc];
[self presentModalViewController:navController animated:YES];

在展示你的 MailServicesController 之后,它现在拥有 UINavigationController 的所有属性

在 MailServicesController 中推送 loginViewController 时只需使用

LoginViewController *vc = [[LoginViewController alloc]init];
[self.navigationController pushViewController:vc animated:YES];

同时弹出LoginViewController

- (void)dismissView //called by a button in my custom toolbar
{

    [self.navigationController popViewControllerAnimated:YES]; //is called but does nothing
}

【讨论】:

  • 谢谢,在我以 MailServicesController 作为根目录初始化导航控制器后,如果我尝试以模态方式呈现 MailServicesController,它会崩溃。
  • 检查我更新的答案。它应该工作。请删除您用于在 MailServicesController 中创建 UINavigationController 的代码
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-09-21
相关资源
最近更新 更多