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.
Related
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.
In my app I have this storyboard:
and I would like to add a back button from the second table view back to the first. So I inserted a Navigation controller in order to have a navigation bar in the second table view ad I have created a segue with its identifier from the second table view to the first. But then how can I add a back button? I have tried to drag a button from the library into the navigation controller but it won't let me do it...I had already done this but in this moment I can't remember how.
Please can you help me?
In above image you shared you are making your tableview controller as root view controller.You have to kept your navigation controller on root. As you can see in attached image and you don't have to make back button manually as navigation controller has its own default back button.
This example is right how to make storyboard.Try it
self.navigationController?.navigationBar.hidden = false
In setting of UINavigationController set up like on screenshot
If you're using a navigation controller and its default navigation bar, you don't add an explicit back button--the navigation bar does it for you. You can add a UINavigationItem to your view controller, on which you set a title, back button title, etc.
So I have a tab bar controller that holds a search view and a profile view. When I click on one of the cells in the search view I want to go to another view controller, still have my tab s on the bottom and maintain the user's ability to click a back button to go back to the main view.
I've achieved the back button part, but I haven't achieved the maintaing tabs part.
This is what I've tried -
-(void)displayCardController{
if(self.userProfile == nil){
[self.tabBarController setViewControllers:#[self.searchViewController, self.loginViewController]];
[self.searchViewController.navigationController pushViewController:self.searchViewController.detailController animated:YES];
} else {
[self.tabBarController setViewControllers:#[self.searchViewController, self.profileViewController]];
[self.searchViewController.navigationController pushViewController:self.searchViewController.detailController animated:YES];
}
}
The idea is - set the tab to have my controllers, and then push what I want to be on top. That doesn't work.
How do I achieve this?
It looks like the problem is that your first tab controller child, self.searchViewController, has a navigation controller. If you want to be able to push onto this controller while still staying inside the tab controller, you need the search view controller (or whatever is the first tab controller child) to be a navigation controller.
Note that its navigation bar can be hidden, so it won't look like a navigation controller, but when you push, you can show the nav bar and so give the user a clear way to get back.
Alternatively, use a different interface. What I do, for example, when I have two tabs and one of them needs to change temporarily, on the iPhone, is use a presented view controller: instead of push/pop, I use use present/dismiss. On the iPhone, this hides the tab bar, but we return to the same place when we're done so the interface is clear. (On the iPad, a presented view inside a tab bar controller does not have to hide the tab bar.)
I would like to introduce in my app a View that will contains both navigation bar and a tab bar at the bottom. View contains a Table View with multiple entries and once user tap on a cell a push segue takes him to another view with details regarding the cell he has previously tapped. If he decides, user can go back to parent view by tapping on 'Back' button of the navigation bar on top. In addition to this, I would like my view to have a tab bar at the bottom with extra tools for the user. So, if he decides to check the 'Creator' of the app, he can by simply tap on 'Creator' TabBarItem at the bottom.
I would like to ask you what is the best way to achieve the above. I have already tried to use UITabBarController combined with UINavigationController. Didn't achieve what I was looking for because I would like the view with the table on it to be independent from the TabBarController and NOT a part of it (by part I mean by accessible through tabs).
Do you believe a UINavigationController view with UITabBarView would be a better choice?
UPDATE
What I mean by, "independent from the TabBarController and NOT a part of it":
Once the app loaded, I would like to see my main view (with table) contains Navigation Bar on top and Tab Bar at the bottom. However, I don't want to see the first tab of the Tab Bar selected because my main view will not be accessible through tabs of the Tab Bar but through Navigation Bar. If, for example, I am in Main view and tap on 1st tap, I would like to move to another view that will contains some other info.
Option 1:-
Create a tab bar Controller and on that TabbarController assign your navigation Views.
say nav1 with tab1 , nav2 with tab2...
Option 2:-
Create a Navigation View Controller and than add the tabbarcontroller on that navigationView Controller by using addSubView.
So when the user clicks on a row in a table u will go to a different View which doesn't have the TabbarController and when the user comes back he will again see the TabbarController.
This is what I will do:
First I will subclass UITabbarController and create for example ParentTabBarController. This controller will contain all the tabs necessary and what they will do if they are clicked so on.
Next for each viewcontroller I create, I will subclass from this ParentTabBarController so that the tabs are already in. You can add additional functionality or override it depending on your situation.
In your appdelegate pass in a navigation controller and every time push and dismiss the viewcontrollers you created in second step.
Hope this helps..
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)