TabBar disappear after Push Segue - ios

This is the current layout for my application. As you can see, I have a ViewController that is embedded in a TabBarViewController. You can see I have two tab bars in both of those bottom view controllers but only the first one shows up. In the second view controller after the push segue, the tab bar disappears. Why is this?
I added the properties for the First view controller and it is not set to hide the bottom bar during the segue so I am confused as to why it would disappear after the segue. Any ideas?

You'll need to wrap your tabBar's root viewControllers in a UINavigationController. So your UITabBarController would actually be pointed at the Navigation Controller. Then as you move around in that navigation controller, the tab bar will stay in place.
To fix this in your application, select your view controller in storyboard, then click "Editor" -> "Embed In" -> "Navigation Controller".
Here's a visual representation I just threw together for anyone else who comes across this problem. If you remove the "NavigationController" in the storyboard shown below, the tab will disappear when you click the button in "First View". With the navigation controller, you will maintain the tab bar. Hope this helps.

Try set self.tabBarController.tabBar.translucent = NO; in viewWillAppear

You could also try to dismiss the views by adding an outlet/action. For example, I experienced an issue where I had a TabBar view controller and needed to segue between 2 different views (ImageViews) on one of the tabs and as soon as I did a traditional segue, the whole tab bar disappeared. I had created the following "Back button" to clear the view:
#IBAction func backBtnPressed(_ sender: AnyObject) {
dismiss(animated: true, completion: nil)
}
Note: It is an important practice to clear views out as they will stack up overtime and will reduce the performance of your app.
Technical Info:
https://developer.apple.com/reference/uikit/uiviewcontroller/1621505-dismiss
Not sure if this helps but worth mentioning!

Related

Back button in the Detail view

I'm struggling with "Master-Detail" concept and almost everything works as expected except one little(but important) nuance. What should I change on the storyboard to have Back button on Detail view(the right corner at the bottom on the screenshot)?
Thanks in advance.
This is an older question, but I just ran into the same thing. The issue is you do not need the navigation controller at the bottom right. Since that is a new navigation controller it will not have a back button, because it only contains one item in its stack.
Remove the bottom right navigation controller and just segue directly to the view controller and that will do it.
Additional tip... to remove the navigation controller and preserve the view, delete the link from the navigation controller to the view, and delete the segue links to the navigation controller. Then recreate the segues directly to your view controller.
So far don't get anything straight. If you want like just below screen then you have to hide your navigationItem backbutton in viewDidLoad like this
navigationItem.hidesBackButton = true
Then in storyboard you have add a toolbar and set it's item title 'Back'. You can also set image for it.
Then drag an action from this item and write this line inside that action
#IBAction func fbfdb(_ sender: Any) {
self.navigationController?.popViewController(animated: true)
}
You may get an warning but you will get your desire action
Storyboard

Present Modal for Image Select Erases UI

I have a very simple View controller below. The UI is literally just a single button with the tab bar at the bottom.
import UIKit
class ImageAdderViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
#IBAction func ButtonPressed(sender: AnyObject) {
let imagePicker = UIImagePickerController()
imagePicker.allowsEditing = false
imagePicker.sourceType = .PhotoLibrary
self.presentViewController(imagePicker, animated: true, completion: nil)
}
}
Once the select image from photo library is selected, if I click cancel or select an image it returns to the view. But the view is now empty except for the tab view.
Here is where my confusion begins:
This code works on an empty project with just one controller.
This code works when I segue to this controller from a different controller that has no tab bar at the bottom. At this point the UI with the button that we have segued to also has no tab bar.
This code does not work when I segue to the controller via a controller that has the tab bar.
All segues are push Show (e.g. Push) segues.
In short the same UIViewController works when segued to by one view but not when segued to by a different view.
EDIT 1 Specific Questions
How do I make the view controller work even when segued to by a view controller with a tab bar? Could the tab bar interfere with the presentViewController code?
My Guess
Somehow something from the previous controller with the tab bar is messing up the code on the viewcontroller with the load button, and that something seems to be entering with the tab bar when the Show occurs. How do I prevent this?
EDIT 2 More clarification
When I click cancel or select an image, the view controller that it returns me too is now empty. The button is missing. When I add labels to the view, all added those disappear as well, and it is just white, except the tab bar at the bottom. This does not occur if I segue to the load image view controller from a view without the tab bar.
EDIT 3
The View that does not bring the tab bar with it when segued from, is not segued to via a navigation controller.
The View that does bring the tab bar with it when segued from, is segued to via a navigation controller.
The Former view functionality does not cause the error. But it does not bring the tab bar
The Latter functionality has brings the tab bar and I want that.
EDIT 4
Changing the segue to a modal present on the UI which has the tab eliminates the tab bar but does not solve to UI deletion problem. This means that merely the presence of the tab bar is not causing the problem.
EDIT 5
If I completely delete the navigation controller in the storyboard it all works, but the tab bar is gone. How can I make it work with the navigation controller?

Segue without the tab bar

I have a app that has a tab bar at the bottom.
I am trying to segue to a new view controller via a button that has the code:
#IBAction func moveOver(sender: UIButton) {
self.performSegueWithIdentifier("to-image-select", sender: sender)
}
This works and it segues to the new view, but the tab bar is still at the bottom. How do I make the tab bar not at the bottom? Is there some way of doing a segue that doesnt carry with it the tab bar?
EDIT 1
I do not want the tab bar, I would prefer to have a fully clean UI for this new view. I will have a back button that will take the user back to the previous page in the corner. I am looking into what modally segues are right now.
Will you need your tab bar further in your navigation ?
If yes, you might want to play with the hidden bool property to display it or not.
If no, you could set your segue as presentModally instead of a regular push.
Hope this helps, don't hesitate to provide more information about what your are trying to achieve
You do not have to use tabbar, you can use navigation controller, or present on top. I advise you to try a tutorial about storyboard before jumping in:
https://www.raywenderlich.com/113388/storyboards-tutorial-in-ios-9-part-1
Good luck (:

Programming Transition Loses Navigation Bar

I'm having an issue with my main.storyboard file. I changed the settings of my app so that the start screen is the main.storyboard file, rather than LaunchScreen.xib. The initial ViewController is the NavigationController, and the second is my SplashScreeViewController. (I created my own splash screen in the storyboard so that I could change it with additional code.) I use a line of code in my splash screen to later transition to the second view controller. Here it is:
var controller:UIViewController = self.storyboard?.instantiateViewControllerWithIdentifier("Second") as! ViewController
controller.modalTransitionStyle = .CrossDissolve
self.presentViewController(controller, animated: true, completion: nil)
For some reason, when I transition to that second ViewController, the navigation bar that should be at the top (of the second ViewController) isn't there, opposite of what was shown in the main.storyboard file. I tried to add an invisible, disabled button to the splash screen as to add a connection between the two view controllers, and therefore adding a navigation bar to the second, but when the splash transitions on its own, no navigation bar appears on the second.
Is there a way I could have a navigation bar on my second view controller without dragging one in, nor programming it in? I would like to use the one Xcode provides when you create a new connection between controllers.
Thanks in advance to all who reply.
*(I apologize for the lack of pictures to help describe my problem. I don't have enough 'reputation' to do so.)
You need to embed your Second view controller on a Navigation Controller, and then instantiate that navigation controller instead.
This might solve the problem - It looks like you are presenting a modal view controller when you probably want to be pushing your view controller from your initial navigation controller with pushViewController

How to "virtually" tap back button in Navigation Bar

I have app, where is Segmented Control inside of my Navigation Bar. Under navigation bar I have 3 containers. In these containers I have Table View Controllers. If you tap on segmented control, one TVC appear and others disappear (container1.hidden = true and so on).
Problem is when I press "save" button which is also in navigation controller - button doesn't trigger "virtual push of back button".
I used following code which works in my other projects (its in button's action which is in VC that contains all container views) but not this time:
if let navController = self.navigationController {
navController.popViewControllerAnimated(true)
}
Image for better insight:
UPDATE: Thanks to # Alexey Bondarchuk I solved it. Comments may be confusing so I just recap problem and solution.
Originally, I had ViewController. To this controller I embed in Navigation Controller. To this Navigation Controller I connected segues. And that was mistake.
So I deleted this embed in navigation controller, made (show) segues directly to my View Controller (which is on screenshot). This automatically created navigation bar and last thing I did was that I put navigation item in it so now my code pop right navigationController. Hope that it's understandable.
I have couple ideas:
Your navigationController equal to 'nil' and .popViewControllerAnimated will never invoked. This may happen if you are using UITabBarController. In this case try to use self.tabBarController?.navigationController instead of self.navigationController.
Your controller presented 'Modally'. In this case you can try to invoke navController.dismissViewControllerAnimatedinstead of navController.popViewControllerAnimated

Resources