I have tab bar controller with 3 tabs(all view controllers are embedded in navigation controller) while clicking the 3rd tab am showing a view controller with start button, clicking start it goes to the next controller, from this controller by programmatically am pushing to another vc. Now my issue is when I click the 3rd tab it showing the last pushed controller instead of showing a view controller with start button.
If I double click the 3rd tab it showing the current view controller.
Help much appreciated.
That’s how it is supposed to work, if you want to show the root vc for tab 3 you’ll need to call popToRootViewController() on the navigationController.
aVC.navigationController.popToRootViewController()
You would need to call the above when the relevant tab button is tapped, so you can use UITabBarControllerDelegate to find out when that happens.
Related
I'm working with the Xcode view editor and Swift.
I have my main view which contains a tab bar controller with 2 tabs.
On the second tab, I have a #IBoutlet var myLabel: UITextLabel!. Inside viewWillAppear I put some text in this label.
On the first tab, I have a button which launch a third view through a Push segue, and on this new tab, I have a Back button which gets me back to the main view containing a tab bar controller (through a push segue too).
When I launch my app, go in my second tab, the text of the UITextLabel is changed.
I still can go to my first tab and navigate between them it works.
But the problem is when I click on my first tab's button, then on Cancel, then goes back to my second tab, my UITextLabel doesn't change. And I can't perform any action on it anymore. It's not nil though but it's like it's still connected to the first UITextLabel before the segue and not this one.
Where am I wrong ?
Several things are wrong.
With tabbed apps, Apple says that the tab bar controller should be the root level navigation method for the app. It should always be present, and the user should always be able to tap another tap to switch to another part of the app.
So the first tab should connect to a navigation controller. When the user pushes the button, you should push a new view controller onto that navigation controller. The tab bar will still be visible and enabled, and the user will still be able to switch to view controller one.
Next thing:
You say "I have a Back button which gets me back to the main view containing a tab bar controller (through a push segue too)."
That's very wrong. Back buttons should pop a view off of the current navigation stack. They should not be pushing anything. Any time you use a push segue, you are creating and pushing a brand new instance of a view controller, and leaving the other view controllers in the navigation stack.
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.
I'm looking to create an application with 4 screens. The first screen will have a tab bar controller with two tabs. The second tab will go to 3rd screen. The 3rd screen will be a table view and when a cell is clicked, will push to the 4th screen and then I want to have a back button on 4th screen to navigate back to 3rd screen. The first screen will have a button that segues to the second screen and from the second screen there is a button that segues to 3rd screen which is the table view. The second screen should also have a back button to go back to first screen. How can I implement this via StoryBoard?
There are a lot of tutorials in the Apple developer site... but also on youtube... search for "Storyboard ios" you can find a step by step tutorial on how to manage the tableview controller and additional tableview to show details. I suggest also to look at http://www.raywenderlich.com/
What I understand so far from your question. You should first drag a Tab bar controller, that will by default have 2 tabs. Now on 1st tab or 1st view controller, place a button and make its push relation with the view controller you want. 2nd tab will open 3rd screen. Place a table view in it(view controller with 2nd tab or item). Make push relation from table view cell to the 4th screen(drag view controller and embed this view with navigation Controller). Embed all those views with navigation controller form where you want to turn back to previous view controller. Hope this is what you wanted.
I have figured out my issue. I wasn't using push to segue with my navigation controller and that was throwing everything off. Thanks for the help!
I have a TabBarApplication with four views in the main TabBarItem. The problem comes when I go to any of these views and click in any button to go to another view and when I go back by a button linked to the main view, the TabBarItem of the app disappear!!
For example, one view of the app is a tableView in which each element of the list is linked to his external view and it has a back button that should return to the tableView. All the segues are by modal, not push because push segue crash the application and by modal it runs correctly but the problem comes when I returned by clicking the back button of the NavigationItem in the header of the view to his main view and the TabBarItem of the app is not there, is empty.
Each tab should have the view controller set to a navigation controller, with the view controller you want set as the root view controller of the navigation controller. Now you can use push segues and the standard back button that will be added for you. This will bypass the issue (and work much better for you and users).
You current issue is likely related to not really ever going back. Instead, just always presenting new modal view controllers which replace any existing content on screen.
I am very new to Xcode and have encountered an issue with my app. I am trying to create a tab bar app. On one of the tabs I have a button that brings the user to a different ViewController. I want to have it so the user can select a button that would return them to the tab that had the button. I tried to set up an action from the button to the previous view (the tabbed screen), however the tab bar disappears. I hope this is makes sense.
Here is a link to a screenshot...
Easiest way to do this is to place a UINavigationController as the root view controller of the TabBarController. You can do this in storyboard by simply ctrl+dragging from the tabbar controller to the navigation controller and adding it as a relationship.
Here's an example using storyboards:
The next step is to set the third controller (in this case the table view controller) to your player view controller class.
Then, you can use the default back button and animation that comes with the navigation controller. If you prefer to hide the navigation bar at the top of the screen, then you can use your custom back button to call
[self.navigationController popViewControllerAnimated:YES];
You can also choose custom animations / segues, etc. but using a navigation controller to help you navigate screens is probably the simplest approach.