StoryBoard Navigate to Root View Controller - ios

This is my first time using story board and I've set up like 5 view controllers with UINavigationController with buttons that push to the next view controller..
So I start on VC1 and push to VC2, then click and button and push to VC3, then click a button and push to VC4, and so on... on the last screen (VC5) I have a "home" button that the user can click to go back to the home screen (VC1), I've set it up so it pushes to VC1, the problem is when the user clicks that they are taken to the homescreen but then there is a back button on the navigation bar and they can go back to the last screen? After they click home they should not be able to return to previous screens without navigating through to them like they had the first time!
How can I accomplish this? Thanks! I'm used to working with xib and programmatically controlling the UINavigationControllers so this StoryBoard stuff is very new to me haha!

It sounds like you want an unwind segue. On the VC1 .m file add the following blank method:
- (IBAction)unwindToVC1:(UIStoryboardSegue*)sender
{
}
Then in your storyboard on VC5 Ctrl-drag from your home button to the green Exit button at the bottom of your view controller. Choose the unwindToMainMenu option and it should now go back to the VC1 when pressed and no longer have the back button as it has popped all the view controllers.

I think the method you're looking for is popToRootViewControllerAnimated:
[self.navigationController popToRootViewControllerAnimated:YES];

Related

Branching off from a tab bar controller?

I've got 3 view controllers. Two I have hooked up to a tab bar controller and one that I'm wanting to access when a user selects a cell on the second view controller in my tabbed views.
I'm wanting when the user hits "back" on the 3rd "detail" page for the user to be taken back to the 2nd view.
When I do this by just adding a button and segueing back to the 2nd VC, the tab bar is gone. I tried in my viewDidAppear to unhide the tab bar, but I guess going off of the tab bar controller messes up the navigation.
I tried creating a variable that was like "didHitBack" and on my "back" button on the 3rd view I'm creating a segue back to the Tab Bar Controller, and if "didHitBack" is true I do
_ self.tabBarController?.selectedIndex = 1
which takes me to the second page, but it's loading the first view in then going to the second page which looks bad.
I was thinking maybe there was a way to do "didHitBack" and setting the tab bar's initial view controller to the second one or something, but that all just seems very wrong.
Is there a "proper" way to do this?
To recap I have VC1 and VC2 that are hooked up to a Tab Bar Controller, I have a tableview on VC2 that on didSelectRow I'm going to VC3 which I do not want to be a part of the tabbed view controller, and when I hit back on VC3 I want to go back to VC2.
If you want to build a navigation stack, you should embed your view controller in a UINavigationController
So your tab bar would be hooked up to VC1 and NavVC. The root view controller of NavVC would be VC2.
You can then push a new view controller onto the stack using the navigation controller (or pop the view controller to go back) all within the confines of the tabBar.

How to enable Back Button on Viewcontroller after TabBarcontroller

I am unable to enable back button on HomeViewController and MapViewController. I do have a Splash Screen before TabBarContoller which is the initial ViewController. Everything is working fine except the back button on HomeViewController and MapViewController. Please help me to fix this issue.
You can't show back button on your rootViewcontroller of NavigationController.
Here map or home are rootViewControllers for your navigation controllers so you can't see back button on that controller. If you will push anothe viewcontroller on that I mean on map or home then on that controller you will find back button.
And if your home or map Viewcontroller have back button and after clicking on that on which viewcontroller you will go?
So it is normal behaviour according to your screenshot shows in question.

How to switch from one of Tab bar view to another view using xib

Suppose I have 3 tabs on tab bar controller:
TabAViewController
TabBViewController
TabCViewController
and in tab C I have one button.
When I click on that button then open the another View (CsubViewController which is not TabAViewController, TabBViewController, TabCViewController). How to call that Another View (CsubViewController) on button click?
And how to come back to the same view after back button click.
It depends. If you are using a NavigationController as the root controller, you push the CSubViewController in your current ViewController by
navigationController.pushViewController(...)
and go back with
navigationController.popViewControllerAnimated(...)
which is the simplest way to achieve your goal.
Or you can write your own code and try to present the CSubViewController modally in traditional presentViewController(...) and dismissViewController way.

Linking Button to Next View Controller

I can't seem to figure out for xcode 6 how you would connect a button to go to the next view controller. In the view controller scene, I have 2 view controllers, VC1 and VC2. VC1 has a button and I want VC1 to be first, and then have the user click the button, which will lead it to VC2. How do I do that? Basically, how do I link the button in VC1 to VC2?
Just Press control key and drag your UIButton onto another view controller
Ctrl + drag from your button to the next controller in the storyboard. Choose "present modally".
Learn about UINavigationViewController, it's maybe more what you're looking for.

How do i avoid IOS storyboard seque loop

My iOS app starts with 2 login screens, then a main "List of accounts" screen. In storyboard I do:
Show "Enter User Reg No" View Controller. (VC1)
Modal Seque to "Enter PAC digits a,b,c". (VC2)
Then Modal Seque to account list. (VC3)
VC3 has a "Logout" button which Modal Seques to VC1.
This is a customer demo prototype. I know it's not correct, as I am building up a loop of VC1,VC2 and VC3s.
What is the correct approach to this? I've read Apple's seque docs, and I still can't find a convincing answer.
The best approach to this would be to use a Navigation Controller with push segues (you can keep the navigation bar hidden if you don't need it), then in your logout button IBAction you just put:
[self.navigationController popToRootViewControllerAnimated:YES];
In order to use a Navigation Controller, you just select your VC1 and then select
Editor->Embed In->Navigation Controller
Edit: I should also probably point out that they're called seGue, with a "g", not seQue!
Don't use any segue to go from a Modal View back to VC1. Just dismiss the modal view:
[self dismissViewControllerAnimated:YES completion:nil];
Usually there's only one modal view. If you must use two, dismiss them both to go back to VC1

Resources