0

I'm using navigation controller:

  1. So, from my first view to I go second view through push view controller

  2. And form second view to I go third view through present model view controller

  3. Now my problem is that, on third view I want to go fourth view through push view controller but nothing happen when I try to push for fourth view, what I do now?

I'm using this code

in my delegate.h file i make a property of navigation controller:

   @property (strong, nonatomic) UINavigationController *navigationControler;
   @property (strong, nonatomic) ViewController *loginViewController;

and in my delegate.m file:

    self.loginViewController = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];
    self.navigationControler = [[UINavigationController alloc] initWithRootViewController:self.loginViewController];
    self.window.rootViewController = self.navigationControler;
    [self.window makeKeyAndVisible];       

and when i go third view through presetmodelviewcontroller like this:

Redeem *redeem = [[Redeem alloc] init];
[self presentViewController:redeem animated:YES completion:nil]; 

and after reached to second view i want to go third view with push view like this

    [self dismissViewControllerAnimated:YES completion:^(void){
     MyPurchaseCards *mypurchase = [[MyPurchaseCards alloc] init];
    [self.navigationController presentViewController:mypurchase animated:YES completion:nil];
}];

but nothing happen and also when i try to get all previous controller like this

   NSArray *arr = self.navigationController.viewControllers;
   NSLog(@"%@",arr);

but array show me null value. WHY?????

Ali Raza
  • 1,183
  • 1
  • 10
  • 15

2 Answers2

0

The problem is that when you use a presentViewController presenting the third controller, your main controller is now the third and it is the controller on the top of the screen (it is called presentedViewController).

If you push the fourth controller on the navigation stack, it is pushed but you can't see it since it is under the third, because the third is your top controller and it is the controller on the top of the screen.

In order to load the fourth controller you have to:

  • dismiss the third and in the completion block...
  • ...push the fourth
Marco Pace
  • 3,820
  • 19
  • 38
  • yes i do as it but this is go back to second view not fourth view check this. [self dismissViewControllerAnimated:YES completion:^(void) { MyPurchaseCards *mypurchase = [[MyPurchaseCards alloc] init]; [self.navigationController pushViewController:mypurchase animated:YES]; }]; @Marco Pace – Ali Raza May 22 '14 at 08:33
  • Very strange, I use the same code in my current project and it works. Can you post the navigation controllers array before the dismissViewControllerAnimated and after the pushViewController? – Marco Pace May 22 '14 at 10:05
  • you mean first i get array of navigation before dismiss.. and send you??? @Macro Pace – Ali Raza May 22 '14 at 10:38
  • Ok, when i get all navigationcontroller and save in NSArray but array showing null value nothing is anything in my array NSArray *allViews = self.navigationController.viewControllers; NSLog(@"%@",allViews); @Marco PAce – Ali Raza May 22 '14 at 11:17
  • Mmm there is something strange. Can you post some code of your implementation please? Perhaps it is a simple fix reading the code. – Marco Pace May 22 '14 at 11:56
  • in my delegate.h property (strong, nonatomic) UINavigationController *navigationControler; property (strong, nonatomic) HomeViewController *homeViewController; and in my delegate.m self.loginViewController = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil]; self.navigationControler = [[UINavigationController alloc] initWithRootViewController:self.loginViewController]; and after presenmodelview controller my all viewcontrollers in null @Marco Pace – Ali Raza May 22 '14 at 12:04
  • Can you modify the first post? It very hard to read it on a comment... Please insert also the methodwhere you present 4th controller and qhen you dismiss it - more code is better :) – Marco Pace May 22 '14 at 12:09
  • I've 2 questions. FIRST: the Redeem *redeem, where is presented? Is that code user in your navigation controller, first, second, third or fourth view controller? SECOND: where is dismissViewControllerAnimated used? Is that code user in your navigation controller, first, second, third or fourth view controller? – Marco Pace May 22 '14 at 12:28
  • @AliRaza unfortunately I can't since it is a code of my work. – Marco Pace May 22 '14 at 12:29
  • when i am on third view there i use dismiss. and Redeem is presented in dismiss block – Ali Raza May 22 '14 at 13:01
0

My guess is that your third view controller is not wrapped in a navigation controller. Instead of pushing straightly the third view controller, you might want to create a navigation controller with the third view controller as a root view controller. Then you'll be able to push your 4th view controller with the code you mentioned.

MartinMoizard
  • 6,600
  • 12
  • 45
  • 75