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

  • SEARCH
  • Home
  • 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 8239193
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T20:03:58+00:00 2026-06-07T20:03:58+00:00

I have the following code: -(IBAction)showAlertView:(id)sender{ alertView = [[UIAlertView alloc] initWithTitle:@Atualizando message:@\ndelegate:self cancelButtonTitle:nil otherButtonTitles:nil];

  • 0

I have the following code:

-(IBAction)showAlertView:(id)sender{

alertView = [[UIAlertView alloc] initWithTitle:@"Atualizando" message:@"\n"delegate:self cancelButtonTitle:nil otherButtonTitles:nil];

spinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];   
spinner.center = CGPointMake(139.5, 75.5); // .5 so it doesn't blur
[alertView addSubview:spinner];
[spinner startAnimating];
[alertView show]; 
}


-(IBAction)getContacts:(id)sender {

[self showAlertView:(id)self];

ABAddressBookRef addressBook = ABAddressBookCreate( );
CFArrayRef allPeople = ABAddressBookCopyArrayOfAllPeople( addressBook );
CFIndex nPeople = ABAddressBookGetPersonCount( addressBook );

I want to show the alert before the rest of the IBAction begins, but im seeing the alertView only at the end of the IBAction. What am I doing wrong?

EDIT: i have:

-(IBAction)getContacts:(id)sender {

// display the alert view
[self showAlertView:self];

// do the synchronous operation on a different queue
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{

ABAddressBookRef addressBook = ABAddressBookCreate( );
CFArrayRef allPeople = ABAddressBookCopyArrayOfAllPeople( addressBook );
CFIndex nPeople = ABAddressBookGetPersonCount( addressBook );

....

if ([contact length] == 8) {

            NSString *first = (NSString*)ABRecordCopyValue(person, kABPersonFirstNameProperty);
            NSString *last = (NSString*)ABRecordCopyValue(person, kABPersonLastNameProperty);
            NSString *phone = contact;
            ContactInfo *user1 = [[ContactInfo alloc] init];
            user1.first = first;
            user1.last = last;
            user1.phone = phone;
            user1.person = person;
            user1.phoneIdx = j;
            user1.book = addressBook;
            NSLog(@"phone is %@", phone);
            [secondViewController.users addObject:user1];
        }
        ABRecordSetValue(person, kABPersonPhoneProperty, mutablePhones, &error);
    }
}
bool didSave = ABAddressBookSave(addressBook, &error);
if(!didSave){
    NSLog(@"error!");
}
dispatch_async(dispatch_get_main_queue(), ^{
    [self hideAlertView]; // or however you want to do it
});

UIAlertView *alertAlmost = [[UIAlertView alloc] initWithTitle:@"Quase Pronto" message:@"Os seguintes contatos não tem código de área. Porfavor, selecione os contatos que você deseja adicionar o digito 9 e pressione Ok (caso não queira adicionar em nenhum, pressione Ok) " delegate:self cancelButtonTitle:@"Ok!" otherButtonTitles:nil];
[alertAlmost show];

[self presentViewController: secondViewController animated:YES completion: NULL];
 });
}

I want the alert to dismiss, and then i can call the table view. Any sugestions?

  • 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-07T20:03:59+00:00Added an answer on June 7, 2026 at 8:03 pm

    Showing a UIAlertView is done asynchronously, so if you call showAlertView: at the top of the method, it’ll show the alert view and then return immediately after, then do the rest of your method.

    If you want the rest of your method to happen after the alert view is dismissed, you need to add yourself as the alert view’s delegate, then implement the method

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

    and do the rest of your stuff in there.


    Edit: Okay, I think I get your problem. You’re doing some time consuming synchronous operation on the main queue and that’s blocking it so that the alert view isn’t displayed until later.

    You should move the time consuming operation to a different queue like so:

    -(IBAction)getContacts:(id)sender {
        // display the alert view
        [self showAlertView:self];
    
        // do the synchronous operation on a different queue
        dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
            ABAddressBookRef addressBook = ABAddressBookCreate( );
            CFArrayRef allPeople = ABAddressBookCopyArrayOfAllPeople( addressBook );
            CFIndex nPeople = ABAddressBookGetPersonCount( addressBook );
    
            // once this operation has finished, you can hide the alert view like so:
            dispatch_async(dispatch_get_main_queue(), ^{
                [self hideAlertView]; // or however you want to do it
            });
        });
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code: - (IBAction)showDirectMessage:(id)sender { DetailMessageViewController * dmvc = [[DetailMessageViewController alloc]
Hi I have the following code: - (IBAction)runTask:(id)sender { NSTask *proc; NSPipe *output; NSData
I have the following code: //View guest list -(IBAction) guestList:(id) sender{ NSString *connected =
I have to following code -(IBAction)doVibrate{ [self vibrate]; } -(void)vibrate{ AudioServicesPlaySystemSound(kSystemSoundID_Vibrate); } both doVibrate
I have the following piece of code - (IBAction)buttonPressed: (id) sender { UIButton *button
I have the following code -(IBAction)ATapped:(id)sender{ //want some way to hide the button which
I have a the following piece of code: -(IBAction)routePicker { UIView *myView = [[UIView
a noob question here. I have the following code: - (IBAction)selectExistingPicture { if ([UIImagePickerController
I have the following code - (void) viewWillAppear:(BOOL)animated { NSLog(@dismiss view); [self dismissModalViewControllerAnimated:YES]; }
The book I'm currently reading has me write the following code : -(IBAction)displaySomeText:(id)sender {

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.