これは、insertDetailsでHUDを即座に非表示にしているためです。
-(IBAction)addtocontacts:(id)sender
{
HUD = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
HUD.labelText = NSLocalizedString(@"Saving_data", @"");
//added my validation here
[self performSelectorInBackground:@selector(insertDetails) withObject:nil];
}
-(void) insertDetails
{
//save contact details in database
// [HUD hide:YES]; remove it
UIAlertView *alertview=[[UIAlertView alloc]initWithTitle:@"" message:@"Contact account details added" delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil];
[alertview show];
}
代わりに、新しいバージョンのMBProgressHUDをダウンロードして、次の方法を使用してください
- (IBAction)addtocontacts:(id)sender {
// The hud will dispable all input on the view (use the higest view possible in the view hierarchy)
HUD = [[MBProgressHUD alloc] initWithView:self.navigationController.view];
[self.view addSubview:HUD];
// Regiser for HUD callbacks so we can remove it from the window at the right time
HUD.delegate = self;
// Show the HUD while the provided method executes in a new thread
[HUD showWhileExecuting:@selector(myTask) onTarget:self withObject:nil animated:YES];
}
デリゲートメソッドを実装します。
MBProgressHUDDelegateメソッド
- (void)hudWasHidden:(MBProgressHUD *)hud {
// Remove HUD from screen when the HUD was hidded
[HUD removeFromSuperview];
[HUD release];
HUD = nil;
}