Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use case for push versus modal segues?

Let's say, I have a scene (pushed view controller with a navigation bar), which displays some tabular data in a table view. In the navigation bar of that scene I have a + sign, which should open a new scene, where the user can add a new item (row to a core data table). In the table view, each row has an arrow on the right side of each cell, which opens a scene where the user can edit that particular item's details. Should I use a push or modal segue for the +? Should I use a push or modal segue for the arrow? What is the "best practise"? I understand the difference between push and modal segues, but I want to know which is better suited for the above use cases.

like image 275
mrd Avatar asked Jan 23 '14 13:01

mrd


People also ask

What is a push segue?

A push Segue is adding another VC to the navigation stack. This assumes that VC that originates the push is part of the same navigation controller that the VC that is being added to the stack belongs to. Memory management is not an issue with navigation controllers and a deep stack.

What is a modal segue?

A modal Segue is just one VC presenting another VC modally. The VCs don't have to be part of a navigation controller and the VC being presented modally is generally considered to be a "child" of the presenting (parent) VC. The modally presented VC is usually sans any navigation bars or tab bars.

How would you explain UIKit segues to a new iOS developer?

When the user interacts with the element, UIKit loads the appropriate view controller, notifies your app that the segue is about to occur, and executes the transition. You can use the notifications sent by UIKit to pass data to the new view controller or prevent the segue from happening altogether.


2 Answers

If you want to follow Apple's best practices, I would suggest the following :

  1. For the "Add" functionality, use a modal segue.
    For example look at the contacts app. Pressing + shows a modal view controller.
    What's the logic ? for start, modal view controllers usually have a "cancel" button, as opposed to the "back" button on a pushed vc.
    When the user presses "back" - he'd expect a way to come back to the vc. Usually "back" saves your data on iOS (auto-saved).
    So by using a modal segue you force the user to submit the form , or cancel. The modal presentation hints that you really need to fill this screen.

  2. For editing - push. but modal could work as well (and you could reuse the same VC).
    Reasons for push :

    • you get a hierarchy of vc's , going back and forward while drilling down.
    • (you should implement) auto saving when going back (just like other iOS apps)
like image 190
Nir Golan Avatar answered Sep 26 '22 20:09

Nir Golan


For adding a new entity to the core data table, on tapping the + button (I assume its a right bar bar button item on the navigation bar), use the modal segue. The view for adding a new row for the enity has to be presented modally and once the save is completed, dismiss the modal view and reload the table view to display the newly added item.

Also for displaying the details of an entity row, use the push segue. A user expects a push action when he selects a table cell and it is the ideal way to do that.

like image 32
shah1988 Avatar answered Sep 25 '22 20:09

shah1988