Here's the setup:
I have a tab bar controller with two tabs. There is a navigation controller on top the second tab, so that I can view details from a table.
On tab #1, I have a button. When this button is pressed, it switches the selected tab over to tab #2.
My problem is this: Let's say I go to tab #2, then I select a line from my table to view the detailed information. Then, instead of hitting the "back" button to return to the base view, I select tab#1. Then I press my button. Tab#2 loads, but it is still showing the detailed view, instead of the table view that I want.
I know how to programmatically press the button.
[self.navigationController popViewControllerAnimated:YES];
But how would I do that when the button pressed method is inside the class for tab#1, which knows nothing of tab#2's navigation controller?
Hope that makes sense. Thanks in advance for any help!
Okay, I finally got it to work. The solution that was suggested gave me a good jumping off point. Here is the code that finally worked for me:
ARFinderAppDelegate appDelegate = (ARFinderAppDelegate)[[UIApplication sharedApplication] delegate];
[appDelegate.booksNavigationController popViewControllerAnimated:YES];
self.tabBarController.selectedIndex = 1;
I had to access the class that contained the NavigationController through an instance of my application delegate. I also had to remove the "objectAtIndex:1" because my application would crash.
Thanks for all the help, this has been a great learning experience for this iPhone development newbie!