0

In My app, I am using push and pop view controller to navigate between UIViewControlers. I have an UIViewcontroller A and UIViewController B. When I click on a button in UIViewcontroller A and use the below code

UIStoryboard *storybord = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
UIViewController *viewController = [storybord instantiateViewControllerWithIdentifier:@"editmessage"];
[self.navigationController pushViewController:viewController animated:YES];

I am able to navigate to UIViewController B. In B, I have a cancel button upon clicking I need to come back to A. The code I am using is below

NSLog(@"You did it");
[self.navigationController popViewControllerAnimated:YES];
NSLog(@"You did it again");

When I press the button in UIViewcontroller A,I am able to navigate to UIViewcontroller B, the viewdidload method of B gets executed. But I am seeing the following message in log file.

2014-01-06 11:40:58.056 padua[5710:60b] View Did Load of editmesage controller
2014-01-06 11:40:58.231 padua[5710:60b] nested push animation can result in corrupted navigation bar
2014-01-06 11:40:58.633 padua[5710:60b] Finishing up a navigation transition in an unexpected state. Navigation Bar subview tree might get corrupted.

When I press the cancel button, the viewdidload of B is again getting executed. I am not sure why this is happening and the app goes to a state where only a blank background image is displayed. Please find the log below. Please let me know where I am going wrong.

CODE

-(IBAction)cancelMessage:(id)sender{
NSLog(@"You did it");
[self.navigationController popViewControllerAnimated:YES];
NSLog(@"You did it again");

}

Logs

014-01-06 11:40:58.795 padua[5710:60b] Unbalanced calls to begin/end appearance transitions for <editMessageController: 0x1900d440>.
2014-01-06 11:41:04.683 padua[5710:60b] You did it
2014-01-06 11:41:04.708 padua[5710:60b] View Did Load of editmesage controller
2014-01-06 11:41:04.769 padua[5710:60b] You did it again
Timothy Rajan
  • 1,947
  • 8
  • 38
  • 62
  • Have you tried `[self.navigationController popToRootViewControllerAnimated:YES];` in your cancelMessage method? instead of `[self.navigationController popViewControllerAnimated:YES];` – Milo Jan 06 '14 at 00:49
  • Thanks for that. But viewController A is not my root view controller. I have some other controllers in the stack which is beneath ViewController A. Can I use popToRootViewControllerAnimated:YES? – Timothy Rajan Jan 06 '14 at 00:51
  • Yes, you can use that as well. `popViewControllerAnimated:` as stated in the documentation, also updates the navigation bar and tool bar. `popToViewController:animated:` does not. – Milo Jan 06 '14 at 00:58
  • I tried that. it went to the root view of the app. – Timothy Rajan Jan 06 '14 at 00:59
  • I need to go the previous view controller i.e ViewController A. Can you please help me. – Timothy Rajan Jan 06 '14 at 01:00
  • Just create ViewController A like you did B and pop to it. – Milo Jan 06 '14 at 01:07
  • @TimothyRajan please send me your code to my address in profile and I will fix and send back. then we will post the answer – Refael.S Jan 06 '14 at 01:07
  • Show me please the code where you initialise the UINavigationController and add it to the window – Refael.S Jan 06 '14 at 01:18
  • Can you please let me know which code you need? Is it Viewcontroller A or ViewController B's code? – Timothy Rajan Jan 06 '14 at 01:19

0 Answers0