0
votes

I have a view controller (MailServicesController) which I have presented modally. I am trying to add to this MailServicesController a UINavigationController (programmatically) that will allow me to push and pop another view controller (LoginController). I have implemented code to do this but am having two specific problems:

  1. The navigation controller pushes the loginViewController onto the top of the stack, but does not animate this transition even though I have set the animation BOOL to YES in the push method.

  2. Once in the loginViewController, when I try to use popViewControllerAnimated, nothing happens (I made my own button for popping, I am not using the nav controller's navbar).

Here is the code I use to create the nav controller inside the MailServices modal view controller:

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

Then in the LoginController, I try to pop the LoginController off the top to reveal the controller I pushed from:

- (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
}

I am not sure what I am doing wrong, can anyone see my mistake?

1
where you initialize the UINavigation Controller either else where - codercat
i only initialize it in above code - jac300
you want navigation throughout the app or this two classes alone - codercat

1 Answers

0
votes

While presenting modally to MailServicesController do like this

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

After that present your MailServicesController, now it have all properties of UINavigationController

In MailServicesController while pushing loginViewController just use

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

While pop up LoginViewController

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

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