Dismissing a UITabBarVC and returning to the sign in screen - ios

I have a sign in VC that pushes a sign up VC; both are under a Navigation Controller. From the sign up VC I call modaling a UITabBar VC with the whole application content. Inside the UITabBar VC I have another VC with a Sign Out method. My question is: how is the correct way to go back to Sign In VC? In this scenario, if I dismiss the UITabBar VC I return to the sign up VC.
I have drawn a diagram that describes the scenario:
Any help will be appreciated.
Thanks,
Marcos

You can change the state of the UINavigationController which is presenting the modal view before dismissing it. For instance calling
[(UINavigationController *)self.presentingViewController popToRootViewControllerAnimated:NO]
from the modal view controller, will result in your underlying UINavigationController to get back to its root view controller, which - in your specific scenario - will be the Sign In VC, so when you dismiss the modal view, the underlying view controller will be whatever you desire.

Related

Objective-C : Modal Segues and Releasing View Controller

The initial view controller on my app is a UITabBarController that displays for logged in users.
For new users, however, my app delegate will point them to a login/registration view controller first:
// New user, show login
self.window.rootViewController = [self.window.rootViewController.storyboard instantiateViewControllerWithIdentifier:#"LoginViewController"];
When the user has completed the login/registration, I then send the user to the tabbar as such:
// Login done, go to main view
[self performSegueWithIdentifier:#"userLoginToMainSeg" sender:self];
However, doing it this way, the LoginViewController is not released (dealloc is not called).
Can someone explain the error in my logic here?
Your modal segue is basically doing:
[loginViewController presentViewController:mainViewController animated:YES completion: ...];
What this means is that mainViewController becomes loginViewControllers presentedViewController:
loginViewController.presentedViewController == mainViewController
mainViewController.presentingViewController == loginViewController
When you're presenting a view controller, the presenting view controller remains in the view controller hierarchy, so that you can later navigate back by calling:
[loginViewController dismissViewControllerAnimated: ...];
So it's perfectly normal that loginViewController is not released, since it's still the window's rootViewController. It's only that loginViewController is obstructed by the presented mainViewController.
If you want to eradicate loginViewController you can set window.rootViewController directly, but that wouldn't animate the transition. You can achieve animation by messing around the view controllers' views, but it's kind of outside the officially sanctioned territory...
IMO the cleanest solution would be to implement a basic container view controller that would be your window's rootViewController, and that could orchestrate the transition between loginViewController and mainViewController by animating their views, and then throwing away loginViewController. It would be kind of a primitive navigation controller without a navigation bar and a navigation stack – just swapping the current view controller with the new one, and throwing away the former.

Replacing a modal view

Setting:
The first view controller for my app is PostsViewController. In viewDidLoad I check if the user is logged in, and if not I preset SignupVC modally. There is an option to login instead of signup of course, and I want to replace the signup VC with a login VC.
I tried making a "show detail (replace)" segue from signup to login VC, but that seemed to present login modal on top of signup VC. The problem with it is after the user is logged in, I have two modals to close, and it seems tricky to close both of them at the same time. Ideally, I want to replace the signup VC with the login VC and only close one modal.
Q1. How come the show detail segue works like present modally segue when applied to a modal view controller?
Q2. How can I replace the SignUp View controller with a login View controller?
Right so after rereading your question and your comment it's clear what you're trying to do here.
Q1: Because you can only present a viewController modally on parent / child views that are modally presented. You cannot push a new viewController onto a modally presented viewController. In order to push a viewController you need a UINavigationController in the view hierarchy (Normally the parent / root view)
Q2: You'll need to present it modally from the signupVC.
Example:
//Somewhere in SingupVC
[self presentViewController:LoginVC animated:YES completion:nil];
Edit
To answer your question in the comments:
No there really isn't a way to dismiss both VC's at the same time.
However there are a couple of ways to do it almost:
You can set a boolean flag on SingupVC that LoginVC was presented. That way, when viewWill/Did appear is called on singupVC and the boolean flag is set to YES you can call: [self dismissViewControllerAnimated:NO completion:nil];
And that way both VCs are dismissed. One when the user dismisses LoginVC via the back button and SingupVC via a if statement in one of the view life cycle methods (if loginVCPresent) dismiss view, type of thing.

iOS - navigation controller back button

I'm developing an iPad App using storyboards. In this app when the user click on "preferences" appear a modal View. One button of this view send the user to another View Controller (but this view has an action bar to go back to his root view controller), but when user taps the action bar back button nothing happen (it's called navigationController popViewControllerAnimated), the user continue in the same view.
Can anyone help me??
Thanks.
UPDATE:
The code to handle the back button:
- (IBAction)btnBackTapped:(id)sender {
[self.navigationController popViewControllerAnimated:YES];
}
I'm using Segue (from storyboard) to call this View Controller:
When the user click on "Meus Favoritos"
They will be redirect to this page:
The segue is with a Modal (from image one to two)...
When you are presenting a View Controller modally, it is likely not within a Navigation Controller, so probably the reference to navigationController in your code is nil, can you check that?
If you are presenting your View Controller modally this will work instead
[self.presentingViewController dismissViewControllerAnimated:YES completion:nil];
However, if you actually want to use a Navigation Controller, you should embed the View Controller that is presenting the Preferences View Controller in a Navigation Controller and present the Preferences View Controller with a show segue instead of a modal one.

Presenting a View controller only in the DetailViewController of UISplitViewController

I am working with UISplitViewController, and I want to present a VC from the detail view controller of the splitViewController. I do it like this:
[self presentModalViewController:VC animated:YES];
also tried this from master VC.
[self.detailVC presentModalViewController:VC animated:YES];
It comes for the full screen I mean it is like presenting from the UISplitViewController itself. I tried changing the modal presentation styles even though I got the same results.
What I want is the VC that is presented should be presented within the bounds of the DetailVC and it can be of DetailVC's entire frame, but not come anywhere near to the MasterVC.
For now I am using UIView Animation to achieve this, any ideas on how to do this just by presenting?
As of Xcode 6:
In the storyboard, select the present modally segue, and go to the Identity Inspector, and choose Current Context for the Presentation option.
Your detail view controller should be inside a navigation controller, then you push your additional view controller into the navigation controller instead of modally.

presentModalViewController on TabBarController App - blank screen after dismissModalViewController

i am using a tabbarcontroller in my app and also want to use a loginview.
I have an LoginController which handles the loginprocedure.
I am presenting the loginView modally.
[self.tabbarcontroller presentModalViewController:loginView animated:NO];
And on other point i am dismissing it(after login is successfull):
[self dismissModalViewControllerAnimated:YES];
After dismiss i have just a blank screen. Thats the blank window in my MainWindow.xib, i have checked it with a testlabel.
Throubles with that. No ideas how to solve this issue.
Two things:
The self.tabbarcontroller should not be instantiating the modal view. It should be the initial view controller that the tabbar controller controls. In the initialization of that view controller, you check for a login session and present the login VC.
Make sure you are dismissing that modal VC you created in the method that presented it. You should have a delegate method for your Login VC (something like loginFinished) that is handled in the VC that presented it.

Resources