How to segue to a view managed by Navigation Controller? - ios

I am working working on an app (iOS 5+) that contains a stacks of views that are managed by a navigation controller:
MyNavController -> MyRootViewController -> MyTableViewController -> MyDetailViewController
I also have view controllers that are not managed by the navigation controller for handling the login (LoginViewController) and registration (RegViewController) of the app.
When the app is launched, it will check if an account has been created. If so, it will seque to the LoginViewController for user login, and then it will segue to MyRootViewController. However, if no login is detected, the user will be presented with the RegViewController scene to create an account. Then, I would like to take the user directly to the MyTableViewController scene, bypassing the RootViewController scene. Is this possible (via Storyboard or programatically)? I have attempted to define a modal segue from RegViewController to MyTableViewController, which seems to partially work - it is able to go to the scene but with the nav bar missing on top of screen. But when I select a table item it fails to go to MyDetailViewController. It crashes with error "Push segues can only be used when the source controller is managed by an instance of UINavigationController."
Any advice?
Thanks in advance.

Select your MyDetailViewController. On the top select editor->embed in ->navigation controller.

Related

Swift - Segue from UIViewController within NavigationController to UIViewController within TabBarController

In my app, things start off with a registration flow, including profile creation, mobile verification, and some further customization which all happens inside separate UIViewControllers managed by a UINavigationController.
However, when registration is completed, I want to leave the UINavigationController and have my final registration View Controller segue to the main TabBarController of the application.
How can I do this?
When you are using a navigation controller that controls more than one UIViewController, you use push push segues. When you want to leave that navigation controller, you will have to use a modal segue. I'm assuming that you are using the Storyboard. When you click and drag from one UIViewController to the next, you choose modal instead of push.
Segues are useful for prototyping, but for a real app I would avoid using segues and control the display of view controllers programmatically.
In your case, you could make the TabBarController the main entry point, and then detect whether the user has registered, and if not, display the registration sequence (modally) on top of this, and when the user completes the sequence, just dismiss it and you'll be back to TabBarController.
Or you could make your initial view controller a blank screen which then decides whether to display the registration sequence or the TabBarController.

Starting app with login page when tab bar controller is present

I have conditional code in my app delegate's didFinishLaunchingWithOptions: method that uses HTTP requests/responses to determine if the user is logged in already. I'm running into serious hierarchy problems, and my question is this: should I be starting my app with the login page (and make the app delegate conditionally load my tab bar when the user is logged in already), or start with my tab bar (and make the app delegate conditionally load my login page)?
This is my storyboard currently
I would make the tab bar controller the root view controller of the window, and present the login controller from the viewDidAppear method (without animation) of the controller in the first tab. Also, you should not go backwards in a storyboard with a segue, unless you use an unwind segue. Segues (other than unwinds) alway instantiate new controllers, so you're not actually going back to a previous controller, you're instantiating a new one. This will cause more and more controllers to be added to your hierarchy as the user navigates back and forth.

About tab bar using storyboard

I want to create an app using storyboard that has login window and tab bar controller.
So the flow will be upon tapping the login button, the app will be redirected to tab bar controller with its views.
I have done this:
But referring to Apple Documentation: UITabBarController
Because the UITabBarController class inherits from the
UIViewController class, tab bar controllers have their own view that
is accessible through the view property. When deploying a tab bar
interface, you must install this view as the root of your window.
Unlike other view controllers, a tab bar interface should never be
installed as a child of another view controller.
So that means I am not allowed to do so?
In addition:
The 3 views that are referred by my tab bar, then each of them has their own child view again, but the tab bar in the child view is gone. What could be happen? Am I missing something?
What I have done in all my apps that are structured similarly is to have the first view controller check for valid authentication and if that fails, present a login VC. That login VC has a delegate defined that will pass back the user credential after a successful login and then dismisses the modal login VC does whatever.
Here is a sample layout:
The delegate protocol looks like this:
#protocol LoginViewControllerDelegate
-(void)finishedLoadingUserInfo:(UserInfo *)curUser;
#end
Where UserInfo is the model I use for the user information (in my case, NetworkID, FullName, etc).
When the user has successfully authenticated, I fire off that delegate method which is handled in the class that presented it. If you need more detail, I can help - but the process is simple.
You can launch your login screen first from the appDelegate and then setup and launch the tabBarViewController after the login is successful.
An alternative design is to do the following steps:
1. set up your tabBarViewController,
2. disable the tabs,
3. launch your login view controller modally,
4. enable tabViewController tabs
Either of these two approaches should work.

Using UISplitViewController in iOS

I want to add a split view controller when the login button is clicked on the login screen (when user is successfully logged in). I want to show another view controller which is a split view controller with a master controller and detail controller.
SplitViewControllers are intended to be used as the root view controller. So you will need to create your login viewController and attach it to the window. Then when the user logs in you will have to remove the login viewController and then create a new SplitViewController and attach that to the window instead.
If you search you should find threads that help e.g.
How to implement SplitViewController on second level.?
I know there are also threads showing how to do this for tabBarControllers and the process is the same.

iphone app with uinavigationcontroller and uitabbarcontroller

I'm new to iphone programming and i'm trying to build an application that has a uinavigationcontroller and the rootviewcontroller is a uiviewcontroller that is basicly a login screen from the login screen the user moves to uitabbarcontroller that has 5 tabs and each tab is a uinavigationcontroller and each navigationcontroller has two button in the navbar one button brings a messages view and the other notifications view each view is a uiviewcontroller.
Now the user can press the message button on every tab and the message view will appear and i want to make sure that if he presses the button on the first tab and then goes to another tab then the message view will disappear and deallocated from memory and when he presses the message button on the new tab then another message view will appear.
I tried the create a single message view in the app delegate and every time that the user presses the message button to call a method from app delegate then in the method i check which tab is pressed and push the view to the navigation controller that belongs to that tab but that doesn't work properly.
You can embed your login views inside the AppDelegate and show them as needed. From there you would load your rootController, which should be your tabBar. Then you can load up your navigation controller inside each tab. One for each tab. Your message view can be called from any of the tabs. Just need to make sure you layer your controllers the right way.
AppDel --> TabBar --> NavController --> Individual Views
Do you realize that you can replace the root view controller in a window? Your app delegate's -applicationDidFinishLaunching:withOptions: method probably does something like:
window.rootViewController = loginViewController;
When you set the window's rootViewController property, the window will add that view controller's view as a subview of itself.
There's nothing particularly special about -applicationDidFinishLaunching:withOptions: -- it just happens to be the delegate method that's called when the app has finished loading and is ready to get down to business. You can set the window's rootViewController property just as well from other methods, so when your login view controller determines that the user has successfully logged in, it can do something like one of the following:
instantiate the tab bar controller and set the window's rootViewController property itself
send a message to its delegate (which would probably be the same object as the app delegate) to inform it that login was successful; the delegate could then install the tab bar controller
broadcast a notification to tell anyone who cares that login was successful, and let someone else install the tab bar controller

Resources