I have a password UIAlertView that we ask the user for. I need to ask it on different views depending on the scenario, from a downloadViewController (after the user downloads their data), when they switch to their data (if the user has multiple accounts, there’s a password per account), and when the app awakes from sleep (from the app delegate).
I have common UIAlertView code that basically checks the database for their password and stuff. Is there a good place to put this common code? I feel like I’m copying and pasting the showing of the alert and the delegate methods for this alert. In certain view controllers, there will be other alerts as well though, and I have to respond to those through the UIAlertViewDelegate in that specific ViewController.
You may create a category like this and then just reuse the code:
*.h file
*.m file
Import the *.h file in your UIViewController class where you need the alert.
Now if you call like this:
it will show your alert and the delegate will be the implemented
IN THE INTERFACE while when you call it like this:
You need to provide the callback
IN THE CLASS YOU CALLED IT FROM, so you can handle whatever the user pressed – differently from what is implemented in the interface.