Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8620685
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T06:38:20+00:00 2026-06-12T06:38:20+00:00

I have a password UIAlertView that we ask the user for. I need to

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T06:38:21+00:00Added an answer on June 12, 2026 at 6:38 am

    You may create a category like this and then just reuse the code:

    *.h file

    @interface UIViewController(Transitions)
    
    - (void) showAlertWithDelegate: (id) delegate;
    
    @end
    

    *.m file

    -(void) showAlertWithDelegate:(id)delegate {
    
        id _delegate = ( delegate == nil) ? self : delegate;
        UIAlertView *alert = [[UIAlertView alloc]
                              initWithTitle: NSLocalizedString(@"Alert Text",@"Alert Text")
                              message: NSLocalizedString( @"Msg Alert",@"Msg Alert")
                              delegate:_delegate 
                              cancelButtonTitle:nil
                              otherButtonTitles: NSLocalizedString(@"OK",@"OK"),nil];
        [alert setTag:0]; //so we know in the callback of the alert where we come from - in case we have multiple different alerts
        [alert show];
    }
    
    //the local callback for the alert - this handles the case when we call the alert with delegate nil
    - (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex {
        D_DBG(@"%i %i",[alertView tag],buttonIndex);
    }
    

    Import the *.h file in your UIViewController class where you need the alert.

    Now if you call like this:

       [self showAlertWithDelegate:nil];
    

    it will show your alert and the delegate will be the implemented

     - (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex
    

    IN THE INTERFACE while when you call it like this:

       [self showAlertWithDelegate:self];
    

    You need to provide the callback

     - (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex
    

    IN THE CLASS YOU CALLED IT FROM, so you can handle whatever the user pressed – differently from what is implemented in the interface.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a password recovery control that is set up to ask the user
I have a user password system where I need to 1) check a user
I am using a custom UIAlertView with UITextField to get password from the user.
I need to load a view after an user has logged id.. To have
SO buddies, greetings. I have some password requirements I need to implement and one
I have a password confirmation component. The user can enter the two passwords manually
I have a password hash that is stored in a table and is put
I have password constraints that i would like to validate: minimum length = 6
I need to have password protection on some web pages outside of the main
I have this password regex for an application that is being built its purpose

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.