我有以下代码:
-(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];
});
}
我希望解除警报,然后我可以调用表格视图。有什么建议吗?