-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 に答える