0

私はiPhone開発に不慣れで、アプリケーションに進行状況ビューを追加したいと思っています。誰かがiPhoneアプリケーションに進行状況ビューを追加する方法と、サーバーの応答がjsonの形式で来るときにこの進行状況ビューが徐々に増加する方法を教えてくれますか。

4

1 に答える 1

0

これはmbprogesshudを使用したサンプルコードです。このメソッドでもprogressviewの進行状況を設定できることを願っています。サーバーからのデータに応じて進行状況を設定する方法については、nsurldelegateメソッドを参照してください。

  - (IBAction)showWIthLabelAnnularDeterminate:(id)sender {
        HUD = [[MBProgressHUD alloc] initWithView:self.navigationController.view];
        [self.navigationController.view addSubview:HUD];

        // Set determinate mode
        HUD.mode = MBProgressHUDModeAnnularDeterminate;

        HUD.delegate = self;
        HUD.labelText = @"Loading";

        // myProgressTask uses the HUD instance to update progress
        [HUD showWhileExecuting:@selector(myProgressTask) onTarget:self withObject:nil animated:YES];
    }



    #pragma mark -
    #pragma mark NSURLConnectionDelegete

    - (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {
        expectedLength = [response expectedContentLength];
        currentLength = 0;
        HUD.mode = MBProgressHUDModeDeterminate;
    }

    - (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
        currentLength += [data length];
        HUD.progress = currentLength / (float)expectedLength;
    }

    - (void)connectionDidFinishLoading:(NSURLConnection *)connection {
        HUD.customView = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"37x-Checkmark.png"]] autorelease];
        HUD.mode = MBProgressHUDModeCustomView;
        [HUD hide:YES afterDelay:2];
    }

    - (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error {
        [HUD hide:YES];
    }
于 2012-05-21T07:41:35.220 に答える