加载符号不会出现在按钮单击上

时间:2013-03-05 08:36:28

标签: iphone xcode

-(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点击时添加了加载符号。我没有加载符号。如果我收到警告信息,我该如何显示呢?

2 个答案:

答案 0 :(得分:1)

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

答案 1 :(得分: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;
}