gpt4 book ai didi

objective-c - 带有 NSURLConnection 的 MBProgressHUD

转载 作者:搜寻专家 更新时间:2023-10-30 19:52:07 26 4
gpt4 key购买 nike

我试图将 MBProgressHUD 与 NSURLConnection 一起使用。

MBProgressHUD报表Demo工程中的例子:

- (IBAction)showURL:(id)sender {
NSURL *URL = [NSURL URLWithString:@"https://github.com/matej/MBProgressHUD/zipball/master"];
NSURLRequest *request = [NSURLRequest requestWithURL:URL];

NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:request delegate:self];
[connection start];
[connection release];

HUD = [[MBProgressHUD showHUDAddedTo:self.navigationController.view animated:YES] retain];
HUD.delegate = self;
}



- (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];
}

运行它,确定模式下的 HUD 旋转良好。

我试图实现这个,但是在这里

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

圆圈是空的,没有填充。

不知道是不是跟请求的url的维度有关。

我请求从我的网站下载一个 plist (~80 kb),但是圆圈一直是空的并且控制台报告

<Error>: void CGPathAddArc(CGPath*, const CGAffineTransform*, CGFloat, CGFloat, CGFloat, CGFloat, CGFloat, bool): invalid value for start or end angle.

我什至尝试这样做:

float progress = 0.0f;
while (progress < 1.0f) {
progress += 0.01f;
HUD.progress = progress;
}

但是现在圆圈已经完全填满了,没有做任何动画。

我认为这取决于请求的 url 的维度,但我不太确定,有人知道如何解决这个问题吗?

最佳答案

我这样解决了这个问题,从 NSURLRequest 切换到 NSMutableURLRequest 并将值 none 设置为编码(以前在 gzip 中)

NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:anURL];
[request addValue:@"" forHTTPHeaderField:@"Accept-Encoding"];

关于objective-c - 带有 NSURLConnection 的 MBProgressHUD,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12235617/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com