Use case for push versus modal segues?

2019-04-20 03:49发布

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.

3条回答
ゆ 、 Hurt°
2楼-- · 2019-04-20 04:21

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)
查看更多
ゆ 、 Hurt°
3楼-- · 2019-04-20 04:34

I hope this quick summary will help you : When you want to show a detail view of a summary view, use a navigation controller and Push Segues. If the "parent" view doesn't really relate as far as data is concerned to the "child" view, then use a modal. A good example for a modal view would be any entry view. This view doesn't really have any relationship as far as data is concerned to the "parent" view., the entry screen will just take data dat from user & will save & can go away & giving control back to parent

查看更多
姐就是有狂的资本
4楼-- · 2019-04-20 04:36

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.

查看更多
登录 后发表回答