1
-(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];
    UIAlertView *alertview=[[UIAlertView alloc]initWithTitle:@"" message:@"Contact account details added" delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil];
[alertview show];
}

我在点击时添加了加载符号。SaveButton我没有得到加载符号。如何让它出现,直到我收到警报消息。

4

2 回答 2

1

在最顶层添加 HUD。例如,如果您在视图顶部有 tableview。然后将其添加到 tableview 上。在我的情况下,我在 tableviews 上添加 HUD 并且它工作正常

于 2013-03-05T08:44:12.337 回答
0

这是因为您立即将 HUD 隐藏在 insertDetails 中。

   -(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;
}
于 2013-03-05T08:42:53.027 回答