Push&流行问题以编程方式创建UINavigationController

时间:2013-11-27 16:44:50

标签: ios objective-c uiviewcontroller uinavigationcontroller

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

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

  2. 一旦进入loginViewController,当我尝试使用popViewControllerAnimated时,没有任何反应(我自己创建了弹出按钮,我没有使用导航控制器的导航栏)。

  3. 以下是我用于在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
    }
    

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

1 个答案:

答案 0 :(得分:0)

向MailServicesController呈现模态时,请执行此操作

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

之后呈现您的MailServicesController,现在它具有UINavigationController的所有属性

在推送loginViewController的MailServicesController中,只需使用

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
}