Tab bar when move to other view controller - ios

I have a problem with the tab bar for my app. When I open my app the bottom tab appears since I am using the Tab bar controller however when I move to another view controller and come back the tab bar is gone. Do I have to do something to the storyboard?

Ok, as I suspected, you're going "back" in an incorrect way. You should never go backwards to a previous controller with a segue unless you use an unwind segue. What you're doing is instantiating a new instance of that controller you think you're going back to -- one that isn't embedded in a tab bar controller. So, you either need to use an unwind segue, or go back in code using dismissViewController:animated:completion: (assuming that you're using modal segues to go forward).

If you navigate to another view with the following:
NamedViewController *svc = [self.storyboard instantiateViewControllerWithIdentifier:#"NamedViewController"];
[self.navigationController pushViewController:svc animated:YES];
and use the following to go back it should work.
[[self.navigationController popViewControllerAnimated:YES] viewWillAppear:YES];

Related

Why is the tab bar not appearing throughout the app?

I have implemented a tab bar, but as I go through the app I am not seeing the tab bar. It disappears after I go to a certain page. This is how I implemented it. I have a tab bar connected to a vc which is embedded inside a navigation controller. So the hierarchy looks like this.
----UITabBarController
-------UINavigationController
-----------ViewController 1 with button to view controller 2 (I can see the tab bar)
----------------View Controller 2 (I can't see the tab bar)
It sounds like the segue that you get from view controller 1 to view controller 2 is a "present" segue, rather than a "push" segue. (If I recall correctly, Apple removed "push" segues from Storyboards recently.) Sadly, "present"ed view controllers appear in front of the navigation controller.
In order to do a "push" segue, you have to do it in code, e.g.:
- (IBAction)buttonTapped: (id)sender
{
ViewController2 *viewController = ...
[self.navigationController pushViewController:viewController];
}
i think you missed to initial tab bar as initial view controller

Back button disappears on show segue

I've read several posts about this issue, but I've been troubleshooting and the previous solutions don't seem to do the trick (i.e. the solutions specify embedding only the parent controller in the navigation controller, which I've tried). To address it as per previous posts, I've removed the embedding of the other views in their own navigation controllers -- but can't then seem to physically draw the segue from one table view to another; or it doesn't show the back button...
Basically, the "Back" button disappears on segue. It isn't seen in the second TableViewController and the last ViewController (on the end). It reappears in the parent, obviously.
EDIT: When I remove the navigation controller from the other two views, then no navigation bar appears on those VCs at all. The bar completely disappears, although it appears on the first one. This is how I have it configured now.
New Storyboard
Navigation Controller follows the Stack theory. When you push something in the stack it will increment the top index count by 1 and pop something in the stack it will decrease the top index count by 1.
In the navigation controller, first controller will be your root viewController. Now When you push new view controller in navigation controller, your top index count will be 2. But you are not pushing the viewController in same navigation controller (let say Stack1) you are creating the new Navigation controller (let say Stack2).
So here you are setting the new controller as the root viewController for new navigation controller(Stack2) and there are no item to pop yet that is why it's not showing the back button.
To Solve these Problem remove the navigation controller from the second and third view controller.
To push you can use segue or you can do it programmatically.
Swift
let vc2 = self.storyboard?.instantiateViewControllerWithIdentifier("ViewController2") as? ViewController2
self.navigationController?.pushViewController(vc2!, animated: true)
Objective C
ViewController2 *vc2 = [self.storyboard instantiateViewControllerWithIdentifier:#"ViewController2"];
[[self navigationController] pushViewController:vc2 animated:YES];
Navigation Controller Guideline
Edit
if you are not able to see the navigation bar on second VC
Make sure you are not hiding it by code in second VC.
Make sure you are pushing the second VC not presenting the VC.
Select VC in Interface Builder -> Attribute Inspector -> Top bar should be inferred.
if you are using segue then segue type(kind) should be Show.

Push new view on front view when using PKRevealController

I am using PKRevealController to display a left side controller.
The PKReveal is connected to my main view controller which is a navigation controller.
I would like when pressing an option from the left side menu it will push a view controller (which is connected to the main view using segue - I use Storyboard).
I'm trying to make it happen from the left side VC - I use the PushViewController but nothing happens.
I am pretty sure you've already overcome this issue, anyway:
Test the class of your RevealController.frontViewController. If it's a navigationController just call [revealController.frontViewController pushViewController: animated:]
Your reveal controller should be accessible from the leftViewController.
If you use storyboard, just instantiate the viewController you want to push by calling [self.storyboard instantiateViewControllerWithIdentifier: ] then push it from the revealController.frontViewController.
This should work. Don't know if this is what you're looking for. Hope this help.

UIBarButton does not go back to Menu

This may be a simple answer, but I am new to this... my back button in the navigation bar is confused and does not want to go back to the Main Menu. Instead, it goes back to the previous view. How can I specify in my app that the "back" button should always go to to a specific view?
All you have to do is create a UIBarButton and connect an outlet to it. In the action:
-(IBAction)MainMenu
{
[self.navigationController popToRootViewControllerAnimated:YES];
}
If you want to go back to the root controller:
popToRootViewControllerAnimated:
Pops all the view controllers on the stack except the root view controller and updates the display.
[self.navigationController popToRootViewControllerAnimated:YES];
If you want to go back to an specific controller:
popToViewController:animated:
Pops view controllers until the specified view controller is at the top of the navigation stack.
You will have to create a new outlet in your view controller to handle the button press. Then use the code NSElvis posted in his answer to pop to root.

Segue to TabBar Controller

I'm using the following code to perform a segue to another view controller:
[self performSegueWithIdentifier:#"BackSegue" sender:self];
This works fine when the destination of "BackSegue" named segue is another view controller (one of the tabs, actually) but I need to display the tabs at the bottom so transitioning directly to this view controller won't work as there will be no tabs. Is it allowed/possible to segue to a tabbar controller? Is anything wrong with this specific code or would it be something else I'm doing?
Edit 1
The TabBar controller has no .m/.h files and is never declared programmatically, but I'm pretty sure the segue is set up correctly in the storyboard to the best of my knowledge (the same way it was set up earlier directly to the other viewcontroller).
You can segue directly to a UITabBarController. Just change the segue in your storyboard. When the segue occurs, it should load the tab bar controller, and consequently the tab bar at the bottom of the screen and the first view controller's view associated with the tab bar controller.
In order to segue to the specific tab in the tab bar controller:
You need to add the selectedIndex=1
Add these lines of code for segue:
UITabBarController *loadTabBar = [self.storyboard instantiateViewControllerWithIdentifier:#"TasksAppsTabs"];
loadTabBar.selectedIndex=1;
[self presentViewController:loadTabBar animated:YES completion:nil];

Resources