I want my iOS app to follow the common pattern of having a main view where signing up or signing in is required to access the app, so if it is the first time the app is run in the device or the user is not logged in, that is the view displayed, and another app view is displayed otherwise. "Sign up" and "Sign in" buttons in main view may navigate to the corresponding forms, or they may show them modally. Once the user access the app, it should be tab based, similarly to Twitter app.
My question is: what should be my rootViewController? A UINavigationController where to push the main view if there are no user's credentials, and the UITabBarController if there are? Or should I set the rootViewController dynamically in the app delegate depending on having credentials or not?
Thanks
I recommend the second solution, use the login screen as root first and on login, change the rootViewController. You can animate this the same way as a modal presentation is animated.
Embedding UITabBarController in a UINavigationController is against the iOS design philosophy. I'm not sure if you'll get a warning or a black screen but something wrong will definitely happen.
There's no need switching between rootViewController.
The rootViewController should be the root, in your case that's the UITabBarController connecting to theUINavigationController or viewControllerwith the signup sign in forms. If the credentials are there, just skip that view.
Switching between roots sounds a bit off. What if the user signs off? what if the user has multiple accounts and signing in and out? That's a lot of unneeded switches.
According to Apple recommendation, UITabBarController should always be the root view controller of your app. more Interesting reading:
When embedding navigation controllers in a tab bar interface, you
should embed only instances of the UINavigationController class, and
not system view controllers that are subclasses of the
UINavigationController class. Although the system provides custom
navigation controllers for selecting contacts, picking images, and
implementing other behaviors, these view controllers are generally
designed to be presented modally. For information about how to use a
specific view controller, see the reference documentation for that
class.
Link
Related
Say, I have a Login screen, Contacts screen and Settings screen.
Login screen doesn't seem to be used frequently in the app so I suspect it is fine to exclude it from the main navigation flow.
Thus I set Login screen as the app entry point, then put all the rest screens as the children of the Navigation Controller. This way I do login process, then pass the control to the Navigation Controller and it does all the in-app navigation in a regular manner.
I am concerned if I am doing it right way, as probably I should make the Navigation Controller as the entry point and then dispatch all the navigation, even for Login screen, with it.
Is it supposed to have a single Navigation Controller inside an app? If so, is it supposed to have it as the parent dispatcher for all the scenes or is it fine to have some scenes put independent?
Here is the current config:
It's fine to embed multiple navigation controllers. In your case, I wouldn't think there would be any issues with not having the initial controller embedded in a nav controller-- getting back to the log in screen would be as simple as using an unwind segue. Alternatively, making the first VC a nav controller also presents no problem, but in your case it would eliminate the need for a second nav controller, based on your current configuration. I find multiple navigation controllers most useful when I'm using container views, and want to swap out VCs within that container.
That's my 2 cents.
I am developing an iOS app that I have already developed for Android.
The problem is I don't know how to organize my UIViewControllers considering the following scheme of my app pages:
The scheme is simple: there is a login page which leads to the main page. From this main page, there are four buttons which all lead to a specific view hierarchy but at the very bottom of each, the user will be able to go back directly to the main page. Each page accessed by the main page will also have a custom back button (an image of my own)
The question is: is there any benefit in using a UINavigationController (obviously with the main page as its root) in my case? Or can I simply create each Controller and using only Modal Segues?
If your view controllers have a navigation relationship so using UINavigationController is the way to go:
In 'push' segue, you are basically pushing your ViewController into an
already setup "navigation stack". Well, of course, this is under the
assumption that the ViewController that performs the 'pushing'
operation belongs to the same navigation stack as the ViewController
is pushed into. Generally, you push a ViewController if the pushed
ViewController has some sort of a relationship with the pushing
ViewController. This is very common in applications that has a
NavigationController in its system. A good example for a push segue is
a system where you are displaying a list of contacts. And on tap of a
particular contact, you are pushing a VC that has the corresponding
details of the contact.
Example is real world: list of products => product details => product reviews
If you want to temporary present a view controller and the main focus is your view controller but you need to present another view controller to perform a task like "filter" , "login", adjust "settings" then modal segue is the way to go
In 'modal' segue, there is no stack as such. You are presenting a VC
'modally' over the presentee VC, if that makes sense. This can happen
across any ViewController without any relationship rules. The
presenter should take care of dismissing the VC it presented. A good
example for modal segue is login. On tap of login, you are modally
presenting a VC that has no relationship with the presenter.
If your view controllers are not related to each other, but each view controller has his own navigation stack then UITabBarController is the way to go
Storyboards (Xcode): What is the difference between a push and modal segue?
I would say if each of the additional view controllers from the main "home" view controller don't have any children view controllers, then you can just have each button present a view controller modally.
The main difference is if you are using a navigation controller, you can "pushing" a vc onto the navigation stack of view controllers, whereas presenting it modally can be thought of a "one time" action where the user does something on the new screen and has no where to advance to logically (like adding information to a new contact).
You can see this post for a more detailed answer:
What is the difference between Modal and Push segue in Storyboards?
Deciding whether to use a Modal segue vs a Show (push) depends entirely on purpose and context of the user's experience. If you are leading the user down a path which is linear, where each successive VC is diving deeper in to a singular idea, then use Show segues and NavigationControllers. Examples include, Settings app, where you can drill into all the specifics. Most e-commerce app will use a NavigationController to lead the user through a purchase.
If you want to present the user with a single concept, which the user can respond to, or close it to continue using the rest of the app. Then use a modal presentation. Adding a contact in the iPhone is a fine example of this.
Visually, the difference is that a Show segue presents the VC from the right side of the app, sliding onto the previous VC. (If the user has Arabic language turned on, a right to left language, the Show segue will come from the left hand side of the VC) A modal comes from the bottom of the app.
From looking at your drawing, but not know anything else about your app, I think you want to use NavigationControllers. You may also want to consider a TabBarController. If each of these buttons lead the user on various ways of using the app, like mini apps within one big one, then a TabBarController is appropriate.
I have a couple views that come before I want to show my split view, disclaimer and then login. After successful login I want to segue to the the split view controller. However I do not think there is a way in storyboards to segue to a split view controller. How do I get from a normal view into my split view controller.
Sometimes if it seems to cumbersome it may be an indication that one need to look at the problem from a different angle.
Assuming your goal is that of forcing the user to go through the login process,
this is what I would do:
Have your splitView as the default view controller, added in the storyboard and loaded as the app starts
As soon as app is loaded, check for the existence of the user's credential. If you don't find any,
present your login framework modally (full screen to cover any data underneath).
Once the user has successfully logged it, dismiss the modalVC and you will have the underlying splitVC underneath ready for use.
I'm designing an app intended to have the following navigation structure: I need to have a welcome view with "Sign up" and "Sign in" buttons as most of apps have:
This view does not show any navigation bar, as it seems to be the common thing. If "Sign In" tapped, then the login view will be presented modally:
And if "Sign up" tapped, the welcome view navigates to a form requesting user input to create an account:
Then, once the user logs in and enters the app, I'd want it to have side menus similar to Facebook, YouTube or Spotify:
Being the central panel a UINavigationController. Left side panel I think it usually is an 'UIViewController'...
The point is, I donĀ“t know what the rootViewController of my app should be, and what hierarchy of view controllers should I have. I've thought about a couple of possibilities:
1) Being the rootViewController an UINavigationController, push the welcome view hidding the navigation bar (is that possible?), presenting the "Sign In" view if needed or pushing the "Sign Up" view. Once the user has logged in, pop these views from the rootViewController, that is a UINavigationController, and then push in such navigation controller the custom view controller managing the side menu stuff.
2) Being the rootViewController the side menu custom view controller, and setting as its central panel an UINavigationController. Push there the welcome view and so on, without setting any view controller for the left/right panels, and then when user has logged in, pop those views from the central panel's UINavigationController, push there the corresponding view, and now setting the left/right panels
I hope I've explained myself. Maybe there is another and better approach to handle this scenario. Does somebody implemented an app like this? I need help with this issue, and also I'll appreciate being recommended a custom library/control providing the side menu stuff from someone who has used one and it is easy to use and customize. I know there are lots of them (MMDrawerController, JASidePanels, for example), but I'd like to have some opinions from people that had developed an app with one of them.
Note: I need to support iPad as well, and iOS 5+
Thanks a lot
I would recommend you to have two main ViewControllers, one for login/signup and second one for the main content with side menu. After the user will log in, just change the window rootViewController to the second one.
For the side menu you can use:
JTRevealSidebar for iOS
GSSlideMenu
JASidePanels
MMDrawerController
I've design an app using ECSlidingViewController (created by Michael Enriquez) which works very fine for me and easy to use.
Tutorial also available on youtube : http://www.youtube.com/watch?v=tJJMyzdB9uI
As for Swift, you could use InteractiveSideMenu library as Side Menu. It's quite easy to implement and transition animation looks pretty smooth.
It was a good find for my project.
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.