Setting different view controller for one tab - ios

I have 5 tab in my tab bar controller. Users can use my application as anonymus user. One of my tabs is Login page. if user logged in my application, that tab should be Home page. but I don't know how set different view controller for one tab based on if condition

One of the possible solutions is to use container view controller.
So, your view controller will have 2 embedded view controllers, and in code you can choose between them based on your logic.
There you can find some relevant examples and topics:
https://developer.apple.com/library/content/featuredarticles/ViewControllerPGforiPhoneOS/ImplementingaContainerViewController.html
iOS Switching an embedded view in storyboard
Embed UIViewController Programatically?

Related

What's the best practices on UItabBars in navigationControllers?

I am creating an app using UItabBarController. I have 5 tabBar items at the bottom.
should I wrap navigationController in each item? Is that the best practice, and if not what's the best practice?
The tabs in a UITabBarController represent independent sections within an app. An example is Apple's Clock app. It has 4 tabs which are completely independent of each other.
A navigation controller represents a top-down hierarchy / stack of view controllers (meaning you start with a root view controller and then 'push' view controllers onto the stack. This almost inevitably means that it shows a 'logical flow'. You perform an action like selecting something on a view controller, which takes you into a more detailed view related to the action you performed. An example is Apple's Notes app which shows a list of folders of notes, selecting a folder pushes the screen with the list of notes in that folder onto the navigation stack, selecting a note in that list pushes the note that the user tapped on, onto the top of the list of notes.
Generally you should have tab bar controller as your app's root view controller and then each of the tabs could have a navigation controller as its root. It wouldn't usually have a tab-bar inside a navigation controller.
One case where a tab-bar could live inside a navigation controller is when a tabbed interface is presented modally.
To your question "should I wrap navigationController in each item", I think yes each tab should have a navigation controller as the root if a navigation hierarchy is required in that tab.
Hope this helps you.

Why does a segmented control hide when using a TabBarController?

I want to use a segmented control inside a tab of a UITabBarController on iOS. It seems to work without it, but as soon as I embed it in a TabBarController, the segmented control won't show up in the navigation bar.
Am I missing something or is it just not supported because of some UI-guidelines? I haven't found anything in the Apple Design Guidelines...
This is the working version:
But in this setup, the segmented control does not show up:
First question is: What are you trying to achieve - what interface do you want to provide?
It is very uncommon to have a tab bar controller embedded in a navigation controller.
A tab bar controller is meant to be used as main app navigation. You can find it in so many Apple Apps (Music, Phone etc.)
These Apps have a tab bar controller with multiple navigation controllers. For example your first tab is a navigation controller with a normal view controller as root.
In this controller you then can set you segmented control.
Apple describes this behavior in it's Combined View Controller Interfaces Documentation (https://developer.apple.com/library/ios/documentation/WindowsViews/Conceptual/ViewControllerCatalog/Chapters/CombiningViewControllers.html#//apple_ref/doc/uid/TP40011313-CH6-SW1).
Update
#kaushal answer solves your problem ... yes. But if you will try to style the navigation bar for every view controller contained in your tab view controller (maybe you want to add a button as rightBarButtonItem only for one view controller) this won't work.
If you want a segmented control on every controller of the tab view controller just isolate the code for this control and reuse it in every controller.
This would achieve the same effect but you would have a cleaner software design.
try this :
Navigation bar is common throwout the stack, It will load once. And it was empty for first view. If you want it customisable for particular VC then you have to do it programatically by accessing self.NavigationBar in view did load method.

UINavigationController limited utilization in app design

I am using the NavigationController (Embedded via Editor drop down menu in xCode) to control navigation on sign-up and sign-in views, all from landing view when app first launched.
After user sign-up or login, I would like to initiate a view controller with no relation to the NavigationController. Nonetheless, from Sign-up and Login views, I have a segue that links (upon successful authorization) to the main view of logged in users. How can I remove the navigation controller from a certain part of the application because it is no longer needed? Otherwise, each time I add a new view controller, it shows the navigation bar in it which is not ideal for design.
Thanks and image attached shows what I need illustrated.
As far as I am concerned you can remove only view controller from navigation stack. If you do not want navigation bar to be visible, then just hide it in viewWillAppear of view controller that you want to be without navigationBar.
[self.navigationController setNavigationBarHidden:<#(BOOL)#> animated:<#(BOOL)#>]

iOS views navigation best practices

I'm very new in iOS dev (but have more then 10 years overall experience with other platforms so it should help). Now I have to create relatively complex iOS application and do it very fast :).
I created application based on 'Tabbed Application' template using storyboard. Then I added login view that uses JSON to communicate with web application. I made this view initial (first that user sees) by moving appropriate arrow from default tab bar controller to my 'login view controller'.
On the login view I have text fields and login button. By clicking button application verifies user's name and password and then navigate him to default tab bar controller (created by Xcode). I do it with this code:
WPFirstViewController *fvc = [self.storyboard instantiateViewControllerWithIdentifier: #"TabBars"];
[fvc setModalTransitionStyle:UIModalTransitionStyleCoverVertical];
[self presentViewController:fvc animated:YES completion:nil];
Everything works fine, but I'm confused than I didn't use graphics lines between views on storyboard and I'm not sure that my approach is correct.
So, questions is how should I navigate user from the login view to tab bar controller? What is the best way in my case? And also, how for example should I navigate user from one of the tab view controller pages page (for example, by clicking button 'Settings') to corresponding view and then back? Maybe somebody could share a link to some good article.
Sorry for the long text. Thank you in advance for your help!
Modal view controllers are supposed to be used for cases where you need to get some critical information from the user (or present some to the user), without which you can't continue with the app. A log in controller would be a good choice for a modal view controller, but your main controller, your tab bar controller isn't. It would be better to present the login controller modally from the controller in the first tab of your tab bar controller. If you do this from viewDidAppear, and with no animation, it will be the first thing the user sees. When the user successfully logs in, just dismiss that controller, and you'll be ready to go in your first tab.
I'm not sure what you mean by your second question. The user navigates between the tabs by clicking on a tab -- you don't need to do anything in code for that.
I would advise you not to use storyBoards. Also, if you are planning to have a navigation controller on your app, then you will definitely use the feature of pushing view controllers on a self.navigationViewController of your view controller. It's easy to use, really easy!!
Typically, login view controllers should be modally presented with: presentModalViewController:animated:
In regards to your UITabBarController, each tab can be a UINavigationController, which will enable you to maintain a stack of UIViewControllers.
All the remains is determining whether the view controller you want to present is modal, or part of said stack.

2 tab bar controller, 2 nav bar controller linked to ONE view (storyboard)

I've got a problem with my application UI.
I want to link 2 tab bar controller to one view, but I don't know how to represent it?
To give you the context of my application, I have a series of views controller that give some useful support information for my app. I want theses view to be displayed on both of my tab bar controller menu (one tab bar controller is displayed when the user is logged in, and the other when he's not)
I thought of putting a view controller between the tab bar controller and the navigation controller, which could trigger the view I'm looking to display 'twice', but for some reasons I couldnt get it to work. (I'm not sure if it's the best implementation, too)
Here's a screenshot of what my storyboard look like right now:
http://img836.imageshack.us/img836/5913/41321932.png

Resources