我是 iPhone 开发的新手,想在我的应用程序中添加进度视图,有人可以帮助我如何在我的 iPhone 应用程序中添加进度视图,以及当服务器响应以 json 形式出现时,这个进度视图将如何逐渐增加。
问问题
383 次
1 回答
0
这是使用 mbprogesshud 的示例代码,希望您也可以通过此方法设置您的进度视图的进度。参考 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 回答