You need to do 2 actions in a row, that is, for example, close the modal window and return to the last controller from which you push or return and switch to a new one. If I write:

[self.navigationController popViewControllerAnimated:YES]; [self.navigationController pushViewController:testViewController animated:YES]; 

So in the end I get an error.

  • it is not clear here why go to the previous controller in order to switch to a new one? Well, by code, you've already made popViewControllerAnimated and want to make pushViewController in the same method. - tragvar
  • If I, for example, entered cell number 1, and then I need to programmatically move to cell number 2, then I will not move from cell number 1. We must first go back, and then go to cell number 2. That is why. - 97mik
  • hmm .. and if after the first you need to go to the third? - tragvar
  • if it is categorically the second, then you can go to cell +1 from the previously selected one in viewDidAppear - tragvar

2 answers 2

corrected

 UITestViewController * testViewController = [[UITestViewController alloc] init]; [self dismissViewControllerAnimated:YES completion:^ { [self.navigationController pushViewController:testViewController animated:YES]; }]; 

upd: while the author is silent, I will leave the answer so

  • No, you misunderstood me, the controller to which the transition will be made is already known, you just have to make it go out of the one in which it has now entered this famous one. - 97mik
  • > you just need to do to go out of that in which now and went to this famous. those. on some event. we then exit: [self.navigationController popViewControllerAnimated: YES]; and pass through the delegate to viewDidAppear (or at your convenience) in the previous one, that we need to go to "this famous" but I think it is not normal, or I still do not understand the task ..)) ps before poppy I never got bye - tragvar
  • > the controller to which the transition will be made is already known, you just need to make sure that it comes out of the one that has now entered this famous one. those. Do you just want to kill the one in which now and go to the new one? if so, this is added to the event on the controller after the cell UITestViewController * testViewController = [[UITestViewController alloc] init]; [self dismissViewControllerAnimated: YES completion: ^ {[self.navigationController pushViewController: testViewController animated: YES]; }]; - tragvar
  • if it helped through the block, then tell me, I will correct the answer - tragvar

Use setViewControllers:animated: with UINavigationController:

 [self.navigaitonController setViewControllers:[[self.navigationController.viewControllers filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"SELF != %@", self]] arrayByAddingObject:newViewController] animated:YES]; 

The last UIViewController in the array is the one on the screen. We filter out the current UIViewController from there using [self.navigationController.viewControllers filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"SELF != %@", self] and add the new new screen arrayByAddingObject:newViewController]