iOS, leftButtonItem 'are you sure?' approach to confirming exit from screen approach? - ios

I'm trying to figure out the standard approach or the best approach.
I don't want my users (children) to accidentally tap the back button and lose what they have entered into a view.
1) In a very old implementation, there's a leftBarButtonItem with an action which shows an alert asking are you sure. But I can't do this without losing the arrow provided by the back button and I don't want to add my own < image.
I've looked into the back button solution of a variable where you keep track of other routes out of the view, then do something in viewDidDisappear, but I won't be able to show an alert and cancel here.
2) I could have my own buttons and not have a navigation bar at all, but the buttons aren't going to look normal.
What;s the standard approach to solve this?

It is not recommended to change the action of the back button. This does include presenting alerts and other UI elements that delay or cancel the back action.
What you can do, is present the controller modally and instead of a back button use a different glyph, such as a cross. Then present an alert when the user taps the button (eg snapchat on creating a snapsterpieces)

Related

Swift Default Swipe Back - Animation

i am trying to make a swipe back animation in my App. It is working completely fine, but there are two problems I have.
The First one is, that the back swipe is working on the complete page and not only on the left side of my display.
And the second questions is, how can I have this normal back swipe animation. In my App it directly pops up.
At the moment I am only using ViewController and to switch between them I use a button with perform segue. But to get back to the pervious page I would like to use this default swipe back animation Apple is having.
Well there are multiple things happening.
the best way to handle this is to embed your first view controller inside UINavigationViewController. You can then push your second view controller and so you will get that Apple back-animation for free.
if you don't want to use NavigationController, you can at least replace that swipe recognizer with UIScreenEdgePanGestureRecognizer, so it will trigger only near the edges of screen. But it will still just pop instantly. You can't easily replicate that back animation... you'd need to use custom transition with
UIViewControllerTransitioningDelegate. And that's not easy.
My advice: learn more about UINavigationController and use it.

iOS navigation views with both "back" and "save" buttons?

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];
}

iOS navigation best practice for adding items

I cannot find the answer to this although I have implemented this rather a few times already, but maybe the wrong way.
Say I have an App for iOS, it has a main screen, which goes to a list, that list has a < back (to main) and an add button. Now when I click < back, I go back to main as that's the pop() from the stack. No issues so far.
Now when I click the add button, that is added to the stack as well; when I click back on that screen I go back to the list which is fine.
The problem is; when I save the new item, I want to go to the detail screen, but I don't actually want to have the add screen on the stack anymore while it will be there. I want the < back button for the detail item pointing to the list.
I know how to do this, but what is actually the best to implement this with the navigation stack?
Well for adding elements the best practice is to present an ModalViewController.
In this way it is not added to the stack.
Update
Let's take as examples simple apps that apple provide with iOS, Contacts app. When you want to add a new contact a VC is presented.
You'll need to implement "Done" or "Save" button that will dismiss the modalViewController and if you want to take the user into detail screen you could post a notification or other mechanism on dismissViewController method's completion block that will push the detail page from the list. But be careful on animations if you dismiss the modal VC animated and push the detail page animated you could get some unexpected behaviour. My proposal is to dismiss the Modal VC animated and push the detail page without animation.
You can override UINavigationController's viewControllers property after you pushed detail view controller. Just get current viewControllers property array, iterate and find the one you don't want to see and remove it. Remember to set viewControllers array again.
https://developer.apple.com/library/ios/documentation/Uikit/reference/UINavigationController_Class/index.html#//apple_ref/occ/instp/UINavigationController/viewControllers

How to change the functionality of back button to display a list?

In my app I use UINavigationController to navigate through hierarchy of views but I encountered a problem - I need to display a list of buttons (when pushed they go to a view controller) instead of the back button.
What is that functionality called? I know how to change the button title and functionality but don't know how to create this list (a good example of my question is the Facebook left bar which shows Friends and other stuff).
In general you're looking for a drawer. That's what it is usually called. There are many libraries/frameworks out there that implement it in a different way so there is no general approach how to "change back button to...".
Check for yourself:
ViewDeck
DDMenuController
PKRevealController
MMDrawerController
Though, here you will find a very good article about very unique way how to implement this "hamburger" icon feature. They provide nice research and you'll find some very interesting information there.
It seems that you need control like MMDrawerController for showing side menu.
Try to make modal segue or hide back button programmatically. Then you add your own button and configure it. Default back button only return you to previous view, you need to make your own.

Make an iOS "forward" button

This is kind of a tough thing to search for because of how general the words are. I would like to make a "forward" button for my app, much like the standard iOS navigation "back" button, but obviously pointing the other direction.
So my question is simple: Is there a standard way of adopting the "back" button style, and simply flipping it to make it point to the right? Or do I have to make a custom button background?
Here is a quick 'shopped screenshot of what I would like.
The back button has a set functionality, it pops the current view controller in the navigation controller and returns to the previous one. A forward button does not have a clear semantic as you can push any view controller onto your navigation controller, which is why UIKit doesn't offer it. You'll probably have to emulate it (copying and flipping the graphics), then systematically push a given view controller when the user presses it.

Resources