I have a UITabBarController with 4 tabs, the first two being "Program" and "Workout".
Whilst on the first tab's view, the user can select the program they wish to perform, and then tap "Perform Workout" which will take them to the workout screen.
My aim is to show the workout screen as part of the same navigation controller as the program select, however I want to update the UITabBarController to reflect the fact that we're now on the workout screen.
The problem is that if I call
UITabBarController *tabController = (UITabBarController*)self.navigationController.parentViewController;
[tabController setSelectedIndex:1];
This opens the WorkoutViewController inside a new UINavigationController, instead of using the old one. I realise that the two UINavigationController problem is happening because of my storyboard, but if I don't have two separate UINavigationControllers, the TabView doesn't stay on top all the time (it disappears after the first push).
How can I update the selectedIndex on my UITabBarController WITHOUT forcing it to load the new UINavigationController?
I think you should disconnect your Workout controller and push this controller using storybord id not from Program controller but change the selected index of tab push this controller to second navigation cotroller
Related
I'm developing a simple iOS app to learn Swift and iOS programming.
I was wondering what would be the "best" way to present, on app launch, a different View Controller than the first one in the Navigation Controller stack.
Consider this storyboard diagram:
The Tab Bar Controller is the initial View controller and "View Controller 1" is shown at app launch inside the navigation controller. Since "View Controller 1" will be almost never used, I'd like to show "View Controller 2" instead, with the "back" button pointing to "View Controller 1". To save time and memory, I'd prefer non to load "View Controller 1" at all, since I already know what data has to be shown in the second view controller.
Both the view controllers are actually Table View Controllers and the selection of one of the cells in the first VC triggers a segue to the second. However the user would usually only need to see the second VC as if the first cell of TVC 1 was selected.
Because you want to be able to "go back" to the first VC, it needs to be put below the second one. My suggestion is to programatically set up the first VC as the root view controller in appDelegate didFinishLaunchingWithOptions and immediately push/present VC2. In this way the first VC won't be shown and therefore costly views loading/laying out subviews can be omitted.
So, here I basically have this layout
but when I build successfully I am not able to see the title of the navigation controller.
What can I do?
This is what you want to emulate:
Set the UITabBarController as is Initial View Controller
add a relationship to each scene, whether it is a UINavigationController or not
If a scene is a UINavigationController, it will behave like any root navigation controller, with its own view stack, back button, an so forth.
Running the app above, then tapping on Item 2 will present this navigation controller:
If you cannot make the UITabBarController the initial View Controller at launch, you can make it become root later on using this technique:
let newViewController = self.storyboard?.instantiateViewControllerWithIdentifier("id")
as? UIViewController
self.view.window?.rootViewController = newViewController
This will present the architecture above, albeit without animation (nor any way to navigate back). Perfect for onboarding or login screens.
Tested on Xcode 7+, iOS 9+
Make your TabBar Controller the initial view, And make sure to remove the navigation controller that's linked to it, Then it should work fine.
So... I've got a ViewController that's being pushed onto a NavigationController. In interface builder I create a separate ViewController and Embed it into a TabBarController and it looks good in Interface Builder.
In my app, I'm trying to go from one of the ViewControllers in my NavigationView to the ViewController in the TabBarController. How would I do this the correct way? I can't just push the view onto the NavigationController, because the tab bar at the bottom won't show up.
Any help would be greatly appreciate.
I believe you're operating with the UINavigationController and UITabBarController in a backwards order to recommended best-practice.
Unless something has changed in the last year or two (which may have happened) the UINavigationController should never have a UITabBarController pushed onto it. If you are using a UITabBarController in your app, it should be the window.rootViewController, and the navigation controller being member of the UITabBarController's viewControllers array.
I'm trying to go from one of the ViewControllers in my NavigationView
to the ViewController in the TabBarController. How would I do this the
correct way?
In that structure, you'd assign your destination view controller as another element of the viewControllers array. Then, in my style, I'd send a NSNotification something like "LaunchOtherViewController" from your first view controller, and thus you have no need for the first view controller to know about the tab bar controller or second view controller. Then have some class that knows about the second view controller receive that notification, and update the selectedIndex of the UITabBarController to that of the second, destination view controller.
Hope that makes sense.
You need to push the TabBarController onto the view. You may need to set the selected view controller of the tab bar, but it's important the tab bar controller be actually pushed onto the navigation stack (or presented modally).
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 have a UINavigationController on some tab of a UITabBar. When I drill down into the navigation controllers tableViews, move it into the more-tab, and then select the entry in the tableview in the more-list, i get the viewController that was visible at the time i left the tab i moved. Clicking on the back-button gets me back to the more-list, with no possibility to get back to the initial root view controller.
It would be perfectly okay for me to have the root view controller appear when i click on the item in the more-list, but i have no idea how to get notified when my viewcontroller is moved, since i am developing a library, and so have no reference to the TabBarController.
One of the ways is to implement tabBarController:willEndCustomizingViewControllers:changed: method in UITabBarViewController delegate. And watch for it. If such thing happend then reset you viewController and navigationViewController. This remove your UINavigationController stack, but application will work correctly.