I am new to iphone so I have a very simple question. I am using a storyboard in xcode 4.2. I have multiple screens with about buttion in each viewController.
Now I have created segues ofc. Each about button i have linked with about viewController. However I am not using a navigation controller.
I have custom made a back button. How can i go back to the screen which brought me on the about section.
Best Regards
If you are modally presenting the new view controllers they can be dismissed using the following.
-(IBAction)myCloseAction:(id)sender{
[self dismissViewControllerAnimated:YES completion:nil];
}
As you are not using navigation controller, u need to manually do the pushing and popping viewcontroller. When u change the viewcontroller, store previous viewcontroller reference in the new viewcontroller and when back button is pressed goto the previously stored viewcontroller.
Related
I don't want to let the navigation controller show its navigation bar in the whole project.
Now there are three view controllers
(1) Login view controller
(2) Sign up view controller
(3) Home view controller.
I just hope to use action(which can be triggered by any kind of event, i.e. drag gesture, not necessary the pressing button) to switch between these view controllers. But I found once I get to the "signup view controllers", I can not go back to the login view controller, since there is no "BACK" navigation bar.
Questions:
How "PUSH" in one view controller, then "POP" in the other view controller?
Or there is some different way to solve this problem?
Thank you so much, any suggestion is great.
To programmaticaly go backward in a navigation controller's navigation stack, call this method:
[self popViewControllerAnimated:YES];
When and where you call this is up to how you want your app to flow. Essentially, the default navigation controller calls this automatically when the navbar's back button is pressed. But if you hide the navbar and still need to pop back, you can call this method to pop back.
As for pushing forward, it's simply a matter of creating a Push segue on the storyboard, giving it a name, and then in your code, call this method:
[self performSegueWithIdentifier:#"segue_YOUR_SEGUE_ID" sender:self];
On the question of your app, what probably makes most sense is for the login view be a view by itself. It should contain a modal segue to a sign up view for new users as well as a modal segue to the home view controller (which may or may not need to be embedded in a navigation controller).
Performing a modal segue works exactly the same as a push segue (if you're using storyboards. Hook up the segue, choose a modal segue, then call the performSegueWithIdentifier: method in your code when you need the segue to occur.
Dismissing a modal view is slightly different, but still quite simple. It goes like this:
[self dismissViewControllerAnimated:YES completion:nil];
It's fairly check to do with an 'if' statement...
if (self.navigationController.navigationBarHidden == NO) {
//YOUR ACTION
}
Hope that helps!
Im relatively new to iOS programming and have been making a recipe based app for the iPad. I've looked around at a lot of answers and can't seem to solve my problem so ill explain how my app is laid out.
Navigation controller -> ViewController -Modal segue -> PreviewViewController -modal segue -> Navigation Controller -> RecipeViewController
Within my RecipeViewController i have a button that when pressed i want it to go back to the "home" screen which for these purposes is the "ViewController".
Here is the code for the button action in "RecipeViewController":
- (IBAction)homeB:(id)sender {
ViewController* viewController = [[ViewController alloc]init];
[self.navigationController pushViewController:viewController animated:YES];
}
However, when i press this button the ViewController is displayed, but the screen is greyed out and i can have no interaction with the screen. I can't post an image of what the screen looks like as i don't have enough reputation yet but i will update it when i can.
I have tried other ways of displaying it such as connecting a segue in the storyboard between the button and the "ViewController" and then activating the segue when the button is pressed. But this messes up other parts of my code as i have to re allocate and initialise the home screen. Would appreciate any help as to why it is coming up with the greyed out screen that cannot be interacted with.
Also just some more notes:
self.navigationController
does not return nil so it is seen, and no errors are displayed when the button is pressed.
Thanks
If you're really doing segues, then I presume this was made in a storyboard. If that's the case, then you should use an unwind segue to get back to ViewController. You do this by adding an IBAction in ViewController that looks like this:
-(IBAction)comingBackFromRecipe:(UIStoryboardSegue*)sender {
NSLog(#"I'm back");
}
The important point is that the sender type be UIStoryboardSegue. Then in IB, in the RecipeViewController, you control drag from your button to the green "Exit" icon at the bottom of the controller. When you let go, you should see the method that you wrote in ViewController -- connect it to that. This will get you back to the same instance of ViewController that you started with.
It's hard to tell without seeing a screenshot, but from what i understand, if you want to go back to the home screen, you shouldn't be pushing a new view controller (unless you really want to add it to the stack?)
To go back to the "home" screen, you should try this:
[self.navigationController popToViewController:viewController animated:YES];
or if your home screen is the root, simply use this:
[self.navigationController popToRootViewControllerAnimated:YES];
Thanks for the responses everyone, i figured out my problem though. My structure was wrong and i realised that i didn't need to have another navigation controller for the Recipe view Controller as i wasn't pushing anywhere from there. So incase anyone else has a similar problem my structure is now as follows:
Navigation Controller -> View Controller -Modal Segue -> PreviewViewController - ModalSegue -> RecipeViewController
I removed the Navigation controller between PreviewViewController and RecipeViewController. This means that they are all modal view controllers. So to get back from the RecipeViewController to the home screen which is "ViewController" i just needed to dismiss the hierarchy of modal views with the following code:
UIViewController * parent = self.presentingViewController;
[parent.presentingViewController dismissViewControllerAnimated:YES completion:nil];
I went back two stages so that both the PreviewViewController and the RecipeViewController where dismissed.
Works great now, thanks for the help anyway everyone.
this if my first post so please be gentle.
I have an iOS 5 app (using storyboards) where I want the user to have the ability to sign out, and with that reset all settings in the app, and also return the user to the very first nib view.
I have already used this code:
[self.navigationController popViewControllerAnimated:YES];
and the problem with this is that it only sends the user back 1 view and not several.
The issue with this is that I have multiple table views that derive from each other and I want the Sign Out button to remain visible in every single one of these detailed views.
Also, this has to work on both iPhone and iPad (Universal)
Any suggestions?
Thanx.
Why not assign a BOOL value YES on button click, then in the viewWillAppear of each viewController:
(assuming BOOL signingOut)
if(signingOut){ [self.navigationController popViewControllerAnimated:YES]; }
Otherwise, just use:
[self.navigationController popToRootViewControllerAnimated:NO];
Why not set the viewControllers array on the navigation controller.
Or send your logout command to the root controller of the navigation controller and have it pop the navigation controller without animation until there are two left. Then pop the second to last one animated. Then you should still get the navigation animation
I have a Table View Controller which I have designed using storyboards. This has an Add button on the navigation bar and I created all this using storyboards. On Add button clicked I have a view controller view to add data and this has a save button on the navigation bar. On Save button Clicked I want the user to save data and return to the TableViewController. All the design was done using storyboards. On Save button clicked I am calling the IBAction save method. I am able to save data but how do I go back to the previous TableViewController programmatically.
thanks
prerna
In your IBAction save method, call:
[self.navigationController popViewControllerAnimated:YES];
Not a Noob as yesterday, but still green.
I have a UITabbarcontoller and a IUNavigationController they seem to work fine. I have a UITableviewController to which I loads my NSMutable array. The user clicks a cell and didSelectRowAtIndexPath xib is loaded onto the stack. I have a 'Learn More' button on the current xib. I've tried a few approaches to load a newer xib when the 'Learn More' button is pressed but have failed. Im thinking it has to do with the Navigation Controller? Do I need to import the navigationcontroller to every ViewControllerSubclass I make? Thanks.
Usually one calls:
[self navigationController] pushViewController:newViewController animated:YES]
to push a new controller onto the view stack. So when the Learn More is pressed, you create a new controller (-initWithNibName:bundle:) and load it using that. Be sure to release the new controller.
Look at the UIViewController documentation for more.