I have an iPhone application that uses a UITabBarController for its primary interface. The application also makes heavy use of modal UINavigationControllers presented from the various tabs.
There is a ViewController that I need to present modally which can be triggered from a wide variety of locations within the application. It seems like a terrible idea to duplicate the code which creates and presents it between all the viewControllers that trigger it. I would like to have this code in a single place and trigger it from whichever viewController wants to present it.
Where should this centralised location be? My root ViewController is a UITabBarController so no good there, and I hate lumping view functionality into the AppDelegate.
I would create a new class file that has a function to present the view you want. That way you only need to write the code once to present the modal view and each view that needs to use it can call the function on the helper class with one line of code.
Implementation:
Then in each view controller import the ApplicationHelper and call the showMyModalView method
This allows you to keep all the view handling code in a separate file to your application delegate.