Is there some way to add a button (not in a navigation view or something like that) that will perform back (meaning, going back to the previous view before the last segue) in an iOS app?
It doesn't have the shape of a back button (it will be fine with simply the word "Back" on it).
I want to put something like that in a bottom toolbar.
Thanks.
Just put a simple button and in its action do:
[self.navigationController popViewControllerAnimated:YES];
Related
I have an app that has a toolbar, but I don't want the bar at the top, in order to free more viewing space. Therefore I have decided not to use a navigation controller. I'd like to add a back button to the toolbar. How would I go about this?
Adding the button is easy enough, and setting the action to performSegueWithIdentifier is all fine, but what happens is that the previous view just gets loaded again, rather than show it as it was, like a true back button. So if I tap on the 10th row on a tableView and go to a new page, when I press the back button it loads the view from the top again, instead of showing it as where I scrolled down to last.
Even though you don't want a UINavigationBar, you do want a UINavigationController in this case, because it manages the 'back stack' exactly the way you want it. Just hide its navigation bar by setting its navigationBarHidden property to true (in the Storyboard or in the viewDidLoad function of the root view controller).
You can then use navigationController.popViewController(true) as normal, in response to the user clicking your custom back button.
I am new to iOS programming and need some help on creating navigation. I have a top-level view, shown on the left. When the user presses the "Create New" button, the app should bring up the "One Journal Entry" view, shown on the right.
I currently have implemented the two views with navigation using a Navigation Controller. The problem I'm finding is that there are now two ways to navigate back: (1) Using the back button in the upper-left and (2) using the "Save" button, which saves to file. I think the back button should go back without saving, or perhaps that should be a "Cancel" button instead, in which case I should not use a Navigation Controller.
What is the standard UI approach for this type of problem?
I think you shouldn't change your views' architecture, it is pretty standard and handy with going back to previous view controller by upper-left button and going back also by save button, which IBAction can look like
-(IBAction)doSaveStuff:(UIButton *)sender
{
// saving stuff
[self.navigationController popViewControllerAnimated:YES];
}
I know that a push segue automatically adds a back button so that the presentee can return to the presenter on click. What I want is for the back button to be available on the first UIViewController of the NavigationController (basically the only view controller in the chain that does not have a back button). How do I force add the back button?
I cannot simply add a custom image because I want the exact same chevron that comes with the iOS back button.
The easiest (yet hackish) way to achieve this is probably adding a dummy view controller in the stack before the actual first one, so you will get a proper back button. Use dummy's backBarButtonItem to customize the button title if you need, and -viewWillAppear: to respond to the button being tapped.
What I want is for the back button to be available on the first UIViewController .... How do I force add the back button
This whole thinking and logic is wrong. This is not how iOS UINavigationControllers work. You have a starting page (mainViewController) in a UINavigationControllers and from there you "move on" to something else. But you always come back to the main view controller. Just think about it, if you put a back button on the main view controller, where will the user go back to?
If you have a situation like this.
SomeViewController --> UINavigationController --> MainViewController
Once user is on SomeViewController and you take him to MainViewController which is part of UINavigationController then back button makes sense.
Just a FYI - you can easily drag and drop a UIBarButtonItem to any UINavigationController in Xcode and call it "Back". You will have to then connect that back button to another view controller.
Maybe it doesn't make sense but why can't you add a custom image? If all you want is "Back" chevron, can't you take a screenshot of this button and then put this image on your custom UIBarButtonItem?
Let's say we've got a few UIViewControllers on the stack of our UINavigationController
How can I define the UIViewController (instead of the previous one) the back button should pop to? (so basically pop two or more instead of one)
Maybe I want the back button to pop back to the root view controller, or just 2 view controllers before.
I know I could create a custom left bar button, but that looses the nice leftwards arrow in the button. And I don't want to use a png graphic to get that arrow back.
Edit:
I want to know how to pop to a certain UIViewController when pressing the back button in the navigation bar. I know how to pop to a certain controller, but not how to have the back button do it.
When you are pushing the viewControllers push all the ones that you may want to go back to and then use popToViewController:animated: to go back to the one that you want. Or use popToRootViewControllerAnimated: to go back all the way to the rootViewController.
i'm building my own navigation between views and i have the navi bar hidden by purpose. still, i need a button inside the view (read outside the navi bar) that would behave like "back" button. is there such method to call that could be assigned to a custom button?
i tried standard push segues, but looping back will create new instances and I just need a standard back behavior (that will destroy the current instance).
i guess it's obvious, but somehow i've been missing it. thanks.
Create a button as normal in your view, then connect it to a method that pops the view from the stack. Something like this:
- (IBAction) pressedBackButton:(UIButton *)sender {
[self.navigationController popViewControllerAnimated:YES];
}