Change View Controller in Tab Bar Controller (Swift) - ios

A little background: My app pops a View Controller that has questions. When the person has answered the question, they swipe and View Controller is presented again, this time with new questions (so it is View Controller with question set 1 -> swipe -> (same) View Controller with question set 2).
This works fine when I do not have View Controller embedded in a Tab Bar Controller. However, when it is embedded in a Tab Bar Controller and I swipe, the View Controller is presented but the Tab Bar Controller is no longer there.
I want the tab bar to remain at the bottom of the screen but I want the View Controller to change upon swiping
func swipeGesture() {
// gesture stuff in here
self.present(ViewController(), animated: true)
}

In Tabbar Controller put a navigation controller. Above the same you can push as much as view controllers of same type or that of different types.
It will work.

Related

Multiple Navigation Controllers with Back Buttons in Swift

I'm making an application that has:
Navigation Controller -> View Controller -> Navigation Controller -> View Controller -> Navigation Controller -> View Controller.
This is making it so that there's no back button on the second view controller, only the third one, and I can't get it to appear. I'm fairly new to iOS and simply want to have a path of view controllers that the user can navigate down and back. Is there a way to add the back button to the second view controller's nav bar? Is there a better way to do this? Is it problematic to just create buttons at the top of views that perform segues?
I found some Objective-C solutions but couldn't find anything in Swift. Thanks for your help!
Remove all the navigation controllers except the first one.Your app must be like this..
Navigation Controller -> View Controller -> View Controller -> View
Controller.
Call segue to move to the other controller .. Just dismiss your controller if you have modally showed them on back button pressed or pop them from
navigationController
if you have pushed them.
Now for Back, you can do it in multiple ways. One of them is, add a view on the top of your controller, add a button on it and implement an action when someone taped it..
I hope you will got that ...

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.

Call master view controller from within detail view of split view controller

I have a tab bar controller with 3 tabs, each embedded within its own navigation controller. This works great, but now I’m trying to put the entire tab bar controller within a split view controller.
The problem is the navigation on the master view for the split view controllers hides the existing navigation for the views inside the tab bar controller. If I hide the master view navigation, I get my tab bar controller navigation back but then I have no way of getting back to the master list. I can add the button back in programmatically but it only works on the iPad.
navigationItem.leftBarButtonItem = splitViewController?.displayModeButtonItem()
navigationItem.leftItemsSupplementBackButton = true
I also tried playing around with the various options for preferredDisplayMode, but again, this only works on the iPad. It has no effect on the iPhone. I can add in a custom button programmatically to the view controller within the tab view controller and call an action from there, but I don't know what action to call. I tried calling the action on the displayModeButtonItem:
splitViewController?.displayModeButtonItem().action
That didn't work either. I would like to be able to just programmatically add back in the behavior of the back button that the split view controller adds on the iPhone.
I ended up scrapping the split view controller and just using anther tab. However I had a similar problem in another app and I figured out a kind of hacky solution. I embedded the tab bar controller itself inside a navigation controller. This causes multiple navigation controllers to appear so I did a check in viewWillAppear to hide whichever navigation controller is causing the issue.
if let hidden = tabBarController?.navigationController?.navigationBarHidden {
if hidden == true {
tabBarController?.navigationController?.navigationBarHidden = false
}
}
This app has a split view controller as the root view controller and then tab bar controllers in both the master and detail views. Every view is embedded in a navigation controller and I just show or hide the navigation bar depending on if I have a duplicate.

How to prevent tabbar from hiding with SWRevealViewController?

I'm trying to find out why any ViewController, that I push onto navigation stack does not show tabbar. Now I have construction like this:
loginVC -> navigationController -> SWRevealVC --> (leftPanelVC and second segue is to tabbarController, which has 4 its own view controllers). When I push view controller from any of this 4 controllers I'm loosing my tabbar and I cannot bring it back. Tried hidesBottomWhenPushed but it didn't work out as expected. Anybody?
EDIT:
What I just tried, was to set connections like this: login -> tabbarcontroller -> as first subcontroller I set up SWRevealViewController and hooked to it front navigationController and rear tableController. Unfortunately it messes stuff a bit, because tabbar now stays always, even on top of rear controller... the look I'm trying to get is interaction like in facebook app, where tabbar is always visible, but as a part of front controller, not overlaying rear.
When I push view controller from any of this 4 controllers I'm loosing my tabbar and I cannot bring it back.
I am not sure what you are doing here, but as far as I understand, you have:
pushed a tab bar controller on to a navigation controller;
from that tab bar controller, pushed a new view controller on to the navigation controller.
It that is correct, than it is normal that your tab bar controller tab bar "disappears" since you are pushing a new view controller (point 2) on to the navigation controller and this will replace the tab bar controller as the top most controller in your navigation controller.
Possibly, what you are looking for can be obtained by embedding a navigation controller inside of a tab bar controller, but I do not have enough info about your UI to be sure this makes sense.

How do you change views from a Tab Bar Controller

I am developing an app that consists of a Tab Bar Controller that points to 3 view controllers (all with tabs). In one of these tab views I've made a button and I want it to open a new view (without a tab at the bottom). This new view would need a navigation bar with a back button to return to the previous view, so I was thinking I need to create a navigation controller?
Essentially this is what I'm trying to do (I apologize for the poorly drawn diagram).
How can I get this new view (entirely independent of the tab bar controller) to display programatically? Would this require a navigation controller?
You are describing a presented view controller. Call presentViewController:animated:completion:.
I very frequently do this with a navigation bar and a Back or Done button, just as you describe. But it's not a navigation controller or navigation interface; it's just a convenient way of showing the user how to get back.
For example, this is a presented view in one of my apps. The top is a navigation bar, and the cancel button gets us back (call dismissViewController...). The rest is a scrolling view (a UICollectionView) of buttons.
[myTabBar setSelectedIndex:1]
You may have to access the tabBar like self.tabBarController so… [self.tabBarController setSelectedIndex:1];
1 is index 1 in the tabbar's stack (this is like tapping a tabBar button manually)

Resources