Navigation back to main view - iphone

I have a root view controller as the navigation controller. In the root view controller nib file I have 3 buttons (button 1, button 2, button3). Each of which has a table view contoller Eg: Flow of the buttons (I have followed the navigation logic such that at any time I can get back to the root view controller by selecting the back button).
On Button 1 click => table view shown ==> detail view shown on item click/selection
On Button 2 click => table view shown ==> detail view shown on item click/selection
This logic holds good for all the buttons. In the detail view I have a button.
What I want is on the click of this button, the button 3 logic should be called such that, when i click or press the back button from the table view of 3rd button, I should get back to the main root view controller with all the buttons visible.
Please let me know how should i go ahead with the same.

I believe you'll want to use the - (NSArray *)popToRootViewControllerAnimated:(BOOL)animated found in UINavigationController. As the name suggests, this will allow you to pop back to the root view controller at any time.

Related

Perform Button Segue to Table View Controller within Navigation Controller

I have a main screen that is a Tab Bar controller with 4 tabs. One of the tabs takes you to a navigation controller where you can click through 3 different Table View Controllers.
I also have a button on one of the other tabs. I would like this button to take the user to the end of one of the Navigation controllers.
I can perform the segue just fine, but when I use the button to get to the View Controller, the tabs on the bottom aren't there, it's just a table.
Is there any way I can segue to a View Controller within a Navigation controller from outside the navigation controller and still have the tab bar showing?
Here are some pictures of what I mean:
See how at the bottom of this page there is the tab bar still? This is when you get there from the navigation controller
And in this picture, there is none (This is the friends page, same as picture above). I arrive at this by using a segue from a button from one of the other tabs.
Please let me know if I need to be more descriptive but I can't figure out how I can make this happen. Thanks for the help!

How to segue modal without losing tab bar controller

Okay, so I want to be able to have a TabBar Controller with two Tabs (like the template in Xcode), but inside the Second tab, I want to have a button that takes the view to a Third View Controller. I want the Third View Controller to have a back button to the Second Tab, I don't want the Third View to retain the TabBar, but when I go back to the Second Tab I want the TabBar to return.
So this is what I actually did, and it doesn't work. I put a button in 2nd view and 3rd view, and I control clicked and dragged to the respective views, and clicked modal. Everything works, except when I go back to the 2nd view I lose the tab bar.
Pictures of what I am talking about:
Screen Shot of Xcode:
Screen Shot of iOS on 2nd view:
Screen Shot of after I click button to go to third view:
Screen Shot of after I Click button to go back to second view. ( lose tab bar !)
http://s13.postimage.org/78gqghflj/Screen_Shot_2012_07_09_at_2_03_41_PM.png
http://s16.postimage.org/gdwus4w6t/i_OS_Simulator_Screen_shot_Jul_9_2012_2_02_50_PM.png
http://s10.postimage.org/5uq3ste7d/i_OS_Simulator_Screen_shot_Jul_9_2012_2_02_57_PM.png
http://s8.postimage.org/gpmsx959x/i_OS_Simulator_Screen_shot_Jul_9_2012_2_03_54_PM.png
You don't need a separate modal Segue back to the Second View Controller, you can just dismiss the modal view controller when "Back to Second View" is clicked
[self dismissModalViewControllerAnimated:YES];

Tab bar controller selectedIndex or SelectedViewController accessor

I have created a tabbar based application which contains, let say, 3 tabs. In my first tab, I have 3 UIButtons. on clicking button 1, a new viewcontroller 1 is loaded and the tab 1 is highlighted as selected. On clicking button 2, a different view is loaded (Viewcontroller 2) and tab 2 should be highlighted as selected tab (Remember, this viewcontroller 2 is not the root view controller of tab 2) and on clicking button 3, again a new view is shown (viewcontroller 3) and tab 3 should be highlighted as selected (Remember, this viewcontroller 3 is not the root view controller of tab 3).
So, what I want to do is, I want a particular tab to be shown as selected (or highlighted), but dont want to load its root view controller.
I have tried using tabbarcontroller.selectedindex = 1 on clicking of button 1, but it went in vain. Because what happened was tab 1 got selected and the view being shown to me was not viewcontroller 2. Instead it was the root view controller of tab 2. Somebody pls get me out of this mess....
If that is indeed your requirement, the best way is to create a 'fake' tab bar using custom uiimageview. You will need three imageview and change the images accordingly as you tap the buttons.

Detecting double tap on a tab bar that pops navigation controller back to root view

My iPhone app has a tab bar controller, and one of the tabs is a navigation controller. When the user double taps on the tab, it causes the navigation controller to pop back to the root view.
My problem is that some of the views in my navigation hierarchy have a specific bar button in their navigationItem associated with that view. So I'm programmatically setting the rightBarButtonItem based on what view was pushed to the navigationController. When the double-tap happens, it pops back to the root view, but not to the right button. The button seems to stay the same as the last view popped that had its own specific button.
So I have a mismatch of the root view with a bar button that goes with another view.
Is there a way to detect when the double tap action occurs? In that case I could reset the buttons on the nav bar to the correct ones. I tried doing it in viewWillAppear/viewDidAppear/viewDidLoad methods, but these don't seem to be called when the tab bar double tap happens.
The safest way to ensure that you always have the right button independent of how the view was made visible (e.g., by popping a child view controller, or by double-tapping the tab bar) is to set the button each time the view becomes visible. Thus, in your root view controller:
-(void)viewWillAppear {
//check button, change if desired
}

Invisible back button when view controller pushed onto navigation controller

I'm using a navigation controller to drill into a detail view when a cell is tapped. When I push my view controller onto the navigation controllers stack, I expect to see a back button that I can tap to pop the previous view off the stack.
The issue is that the back button isn't visible, but when tapping where it should be returns me to the previous view. What's the problem?
Ensure you have set a title for the master view - for example in viewDidLoad add this -
self.title = #"The Title";
Weirdly, if there is no title for the parent view controller on the stack, rather than show an empty back button, the iPhone will not display a button but will allow taps on the area where it should be.
This bugged me for a long time!
At least as of iPhone 3.0, you can also avoid the dreaded invisible back button by setting a title on the root controller's navigation item in your main window's nib (MainWindow.xib in wizard-generated projects).
Lets see if this helps you.
I had the same issue where I used a navigation based application and set up my search, rotation etc..
BUT, when I clicked on the table cell I was directed to the next view but that view did not have a back button present.
I tried to add a title to the back button but that did not work so this is what I did.
I opened the mainWindow.xib file and added a Bar Button Item to the group of other items inisde the window (where the file's owner is located). I then assigned an image to the button (you can add text here if you want).
Then I clicked on the Navigation Item and hit command 2 to open up the Navigation item connections
and chose the back bar button item and dragged it to the bar button item I wanted to use for my back button. And there you have it.