My app has a list of clients in a table view. When you click on a client it takes you to a detailed view controller using a standard navigation controller.
The list view controller allows the user to swipe to delete a client. The detailed view controller has a button to delete a client.
When deleting a client I want to present an action sheet with a several choices.
THE QUESTION: I don’t want to duplicate code in both of my view controllers for presenting the action sheet and handling the results of the action sheet. As both view controllers are deleting a client, the code is identical in both instances. Is there a design pattern that is considered best practice in this case?
Thanks for any help.
I guess you can’t really use one-set of code for UIActionSheet in both viewControllers. But for a very similar situation, my approach was as follows. I hope it helps.
I create my own custom class, e.g. MySortingClass (in my case, it was sorting options, e.g. date ascending / descending, name ascending / descending). This class is a subclass of NSObject.
In my custom class I declare various methods that will return, for example, an array of options title to show to the user, an array of NSSortDescriptors, etc.
In any of my viewControllers that I need to present a list of sorting options to user, I would import MySortingClass, alloc, init, and get an array of options, show them via actionSheet, and send back the response as an index to the MySortingClass and get the appropriate NSSortDescriptor back and re-sort.