私は次のコードを持っています:
-(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 );
残りのIBActionが始まる前にアラートを表示したいのですが、IBActionの最後にのみalertViewが表示されます。私は何が間違っているのですか?
編集:私は持っています:
-(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];
});
}
アラートを閉じて、テーブルビューを呼び出すことができます。何か疑惑はありますか?