简体   繁体   中英

Handling dialogue after Quick Action

I have an iOS app that consists of an "Overview" scene as the initial view controller, an "EntryList" scene, and a "NewEntry" scene. They are organized with a navigation controller and connected in the mentioned order, using show (push) segues. The NewEntry view controller has "Save" and "Cancel" menu bar items that unwind to the EntryList controller.

I added a Quick Action to the app icon that directly jumps into the NewEntry controller by using performSegueWithIdentifier with a segue that goes from the navigation controller to the NewEntry controller.

When the Quick Action is used after the application had been suspended from running, the new NewEntry instance ist pushed onto the navigation stack, regardless of the previous contents. So, even multiple NewEntry instances can be stacked. In this case, any remaining old NewEntry instances could be discarded.

When the Quick Action is used after the application had been terminated, a new Overview instance is always created first (because of being the first actual VC after the initial navigation controller, I suppose?), and then the NewEntry is pushed. No EntryList scene in this case.

When either the Cancel or the Save item is pressed, the NewEntry scene shall be discarded and acted upon appropriately, leaving the user either in the state the app had before, or in the overview scene otherwise.

My questions:

  • What would be the correct behavior an application should perform?
  • How do I achieve that behavior?
  • What is "best practice" to implement all segues, especially when the NewEntry scene is not necessarily pushed after the EntryList scene?

I want to steer clear of "UI spaghetti code", navigation stack hacking, etc.

So, after some trial + error, my current solution is to embed the NewEntry scene into its own navigation controller. This is targeted by "Present Modally" segues from the EntryList and the Quick Action (originating from the main navigation controller). The Save and Cancel buttons do not unwind but instead are connected internally to actions that do the necessary work and finally call dismissViewControllerAnimated() .

Please comment if this is the right way, or if you have better solutions.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM