0

I have a crash when trying to switch to another VC. Here is the structure:

TabBarController [Home, Tab2, Result tab]

from these tabs, I can push a new viewController called addVC which contains a UITextField.

What I want to do, is to be able to follow this sequence: Tab2/Home (step1) => addVC (step2) => Result tab (step3)

To do this, I use this code in addVC :

[self.navigationController popToRootViewControllerAnimated:NO];
UITabBarController *tabbarController = ((UITabBarController*)appDelegate.window.rootViewController);
[tabbarController setSelectedIndex:2];

It works most of the time, but if the focus was in the textfield when I pop then push the result tab, the tab from the step1 is no longer accessible without a crash.

The crash log is:

[addVC respondsToSelector:]: message sent to deallocated instance 0x10977e60

NSZombie tells me that [UITextField canBecomeFirstResponder] has been called, causing the crash.

Since I use a storyboard, nothing except this is done programmatically. I guess my way to go to step3 is not the right one. I'm using ARC and I'm not releasing anything by myself.

Any ideas?

Thanks in advance.

Vico
  • 1,696
  • 1
  • 24
  • 57

1 Answers1

1

For those who could have the same problem, the solution was to use this:

[self.view endEditing:YES];

Before popping anything, else the keyboard is still displayed and that's what causes the crash.

Vico
  • 1,696
  • 1
  • 24
  • 57
  • It doesn't work for me. `[self.navigationController popToViewController:orderEntry animated:YES]; [[[[[self tabBarController]tabBar]items]objectAtIndex:1] setBadgeValue:@"1"]; [self.tabBarController setSelectedViewController:(OrderBookViewController*)[[self.tabBarController viewControllers]objectAtIndex:1]]; [self.tabBarController setSelectedIndex:1];` – Nagarajan Sathish Dec 11 '14 at 06:45