My iOS app starts with 2 login screens, then a main "List of accounts" screen. In storyboard I do:
Show "Enter User Reg No" View Controller. (VC1)
Modal Seque to "Enter PAC digits a,b,c". (VC2)
Then Modal Seque to account list. (VC3)
VC3 has a "Logout" button which Modal Seques to VC1.
This is a customer demo prototype. I know it's not correct, as I am building up a loop of VC1,VC2 and VC3s.
What is the correct approach to this? I've read Apple's seque docs, and I still can't find a convincing answer.
The best approach to this would be to use a Navigation Controller with push segues (you can keep the navigation bar hidden if you don't need it), then in your logout button IBAction you just put:
[self.navigationController popToRootViewControllerAnimated:YES];
In order to use a Navigation Controller, you just select your VC1 and then select
Editor->Embed In->Navigation Controller
Edit: I should also probably point out that they're called seGue, with a "g", not seQue!
Don't use any segue to go from a Modal View back to VC1. Just dismiss the modal view:
[self dismissViewControllerAnimated:YES completion:nil];
Usually there's only one modal view. If you must use two, dismiss them both to go back to VC1
Related
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.
Here is the scenario: I have 2 views, each embedded in a navigation controller. The first nav bar has 1 edit nav bar item, when tapped it goes to the 2nd VC. The 2nd VC nav bar has a cancel and save button, and when tapped should respond accordingly. I want to code the cancel action first, which will just call [self dismissViewControllerAnimated:YES completion:nil] but it is not doing anything...
I have also tried [self.navigationController popViewControllerAnimated:YES] and neither works, please help
BTW both segues are push segues
sounds like something off in you segues ...
i did a quick test in the following way:
create two view controllers in the story board ,each has it own navigation controller.
crate a segue from the first view controller to the second one.
2 in the first view controller i added a bar button that preform the segue from 2.
3 to the second view controller i added a bar button with an action that did : popViewControllerAnimated:YES..
all works fine...
though i don't really understand why you need 2 navigation controllers here....
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.
This is my first time using story board and I've set up like 5 view controllers with UINavigationController with buttons that push to the next view controller..
So I start on VC1 and push to VC2, then click and button and push to VC3, then click a button and push to VC4, and so on... on the last screen (VC5) I have a "home" button that the user can click to go back to the home screen (VC1), I've set it up so it pushes to VC1, the problem is when the user clicks that they are taken to the homescreen but then there is a back button on the navigation bar and they can go back to the last screen? After they click home they should not be able to return to previous screens without navigating through to them like they had the first time!
How can I accomplish this? Thanks! I'm used to working with xib and programmatically controlling the UINavigationControllers so this StoryBoard stuff is very new to me haha!
It sounds like you want an unwind segue. On the VC1 .m file add the following blank method:
- (IBAction)unwindToVC1:(UIStoryboardSegue*)sender
{
}
Then in your storyboard on VC5 Ctrl-drag from your home button to the green Exit button at the bottom of your view controller. Choose the unwindToMainMenu option and it should now go back to the VC1 when pressed and no longer have the back button as it has popped all the view controllers.
I think the method you're looking for is popToRootViewControllerAnimated:
[self.navigationController popToRootViewControllerAnimated:YES];
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.