-1

我正在尝试使用UIActivityIndicator引用此链接(http://www.cocoacontrols.com/platforms/ios/controls/mbprogresshud),但这里有问题。我必须显示一个指示器几秒钟保持不变ViewController,然后它必须导航,但我的代码表现得就像我以前单击按钮时它只是导航和显示指示器。我们可以停止导航几秒钟直到指标过程完成吗?

- (void)myProgressTask {
    // This just increases the progress indicator in a loop
    float progress = 0.0f;
    while (progress < 1.0f) {
        progress += 0.01f;
        HUD.progress = progress;
        usleep(50000);
    }
}
-(IBAction)loginActionforIphone:(id)sender
{

    HUD = [[MBProgressHUD alloc] initWithView:self.navigationController.view];
    [self.navigationController.view addSubview:HUD];

    // Set the hud to display with a color
    HUD.color = [UIColor colorWithRed:0.23 green:0.50 blue:0.82 alpha:0.90];

    HUD.delegate = self;
    [HUD showWhileExecuting:@selector(myProgressTask) onTarget:self withObject:nil animated:YES];


    if([loginText_ipad.text length]<=0||[passwordText_ipad.text length]<=0)
    {
        UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"" message:@"Please enter all the fields" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
        [alert show];
        [alert release]; 
    }
    else
    {
        if(([loginText_ipad.text isEqualToString:@"21770765"]&&[passwordText_ipad.text isEqualToString:@"21770765"])||([loginText_ipad.text isEqualToString:@"21770766"]&&[passwordText_ipad.text isEqualToString:@"21770766"]))
        {


            HPEBDashboardViewController_iphone *dashboardView = [[HPEBDashboardViewController_iphone alloc] initWithNibName:@"HPEBDashboardViewController_iphone" bundle:nil];
            if([loginText_ipad.text isEqualToString:@"21770765"])
            {
                dashboardView.buttonvalue=1;
            }
            else
            {
                dashboardView.buttonvalue=2;
            }
            [self.navigationController pushViewController:dashboardView animated:YES];
        }
        else
        {
            UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"" message:@"Invalid credentials" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
            [alert show];
            [alert release];
        }


    }

   }
4

2 回答 2

1
- (void)myProgressTask {
    // This just increases the progress indicator in a loop
    float progress = 0.0f;
    while (progress < 1.0f) {
        progress += 0.01f;
        HUD.progress = progress;
        usleep(50000);
    }
}
-(IBAction)loginActionforIphone:(id)sender
{

    HUD = [[MBProgressHUD alloc] initWithView:self.navigationController.view];
    [self.navigationController.view addSubview:HUD];

    // Set the hud to display with a color
    HUD.color = [UIColor colorWithRed:0.23 green:0.50 blue:0.82 alpha:0.90];

    HUD.delegate = self;
    [HUD showAnimated:YES whileExecutingBlock:^{
    [self myProgressTask];
} completionBlock:^{
    if([loginText_ipad.text length]<=0||[passwordText_ipad.text length]<=0)
{
    UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"" message:@"Please enter all the fields" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
    [alert show];
    [alert release]; 
}
else
{
    if(([loginText_ipad.text isEqualToString:@"21770765"]&&[passwordText_ipad.text isEqualToString:@"21770765"])||([loginText_ipad.text isEqualToString:@"21770766"]&&[passwordText_ipad.text isEqualToString:@"21770766"]))
    {


        HPEBDashboardViewController_iphone *dashboardView = [[HPEBDashboardViewController_iphone alloc] initWithNibName:@"HPEBDashboardViewController_iphone" bundle:nil];
        if([loginText_ipad.text isEqualToString:@"21770765"])
        {
            dashboardView.buttonvalue=1;
        }
        else
        {
            dashboardView.buttonvalue=2;
        }
        [self.navigationController pushViewController:dashboardView animated:YES];
    }
    else
    {
        UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"" message:@"Invalid credentials" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
        [alert show];
        [alert release];
    }

   }
于 2013-01-23T10:29:16.427 回答
0

像这样改变你的方法:

-(IBAction)loginActionforIphone:(id)sender
{

    HUD = [[MBProgressHUD alloc] initWithView:self.navigationController.view];
    [self.navigationController.view addSubview:HUD];

    // Set the hud to display with a color
    HUD.color = [UIColor colorWithRed:0.23 green:0.50 blue:0.82 alpha:0.90];

    HUD.delegate = self;
    [HUD showWhileExecuting:@selector(myProgressTask) onTarget:self withObject:nil animated:YES];
}


- (void)myProgressTask {
    // This just increases the progress indicator in a loop
    float progress = 0.0f;
    while (progress < 1.0f) {
        progress += 0.01f;
        HUD.progress = progress;
        usleep(50000);
    }
   [self navigate];
}

添加一个新方法,例如:

-(void)navigate
{
   if([loginText_ipad.text length]<=0||[passwordText_ipad.text length]<=0)
    {
        UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"" message:@"Please enter all the fields" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
        [alert show];
        [alert release]; 
    }
    else
    {
        if(([loginText_ipad.text isEqualToString:@"21770765"]&&[passwordText_ipad.text isEqualToString:@"21770765"])||([loginText_ipad.text isEqualToString:@"21770766"]&&[passwordText_ipad.text isEqualToString:@"21770766"]))
        {


            HPEBDashboardViewController_iphone *dashboardView = [[HPEBDashboardViewController_iphone alloc] initWithNibName:@"HPEBDashboardViewController_iphone" bundle:nil];
            if([loginText_ipad.text isEqualToString:@"21770765"])
            {
                dashboardView.buttonvalue=1;
            }
            else
            {
                dashboardView.buttonvalue=2;
            }
            [self.navigationController pushViewController:dashboardView animated:YES];
        }
        else
        {
            UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"" message:@"Invalid credentials" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
            [alert show];
            [alert release];
        }


    }
}
于 2013-01-23T10:11:53.617 回答