I have a UIAlertView that asks a user whether they want to copy a bunch of contacts. After the user clicks "Continue," I want the AlertView to disappear to be replaced by a UIProgressView that shows the rate of loading.
Everything functions properly except that the alert remains on the XIB after the user clicks Continue, and it doesn't disappear until the entire process has run. As soon as it disappears, the UIProgressView bar appears but by then it has reached 100%.
How do I clear the UIAlertView off the screen immediately and show the progress bar growing instead.
Here's the code. Thanks for help.
-(IBAction)importAllAddressBook:(id)sender {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Import ALL Contacts" message:@"Do you want to import all your Address Book contacts? (Please note that only those with a first and last name will be transfered)" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Continue", nil];
[alert show];
[alert release];
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
if (buttonIndex == 0) {
NSLog(@"NO STOP");
return;
}else {
NSLog(@"YES CONTINUE");
importAllContactsProgress.开发者_StackOverflow社区hidden = NO; // show progress bar at 0
[self importAllMethod];
}
}
// method to import all Address Book
-(void) importAllMethod {
importAllContactsProgress.progress = 0.0;
load names etc etc
You'll want to perform the perform the import on a background thread:
[self performSelectorInBackground:@selector(importAllMethod)];
Your import method is blocking the main thread and preventing any UI actions from occurring.
精彩评论