[英]Write file to NSDocument directory show UIProgressView in iPhone?
[英]Upload a file to server to show UIProgressView in iPhone?
我已经通过服务器上传了文件,并且文件可以正常工作,但是我想显示一个进度视图以查看上传状态,如何执行此操作,请帮帮我
提前致谢
我尝试了这个:
[body appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"file\"; filename=\"%@\"\r\n",file] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[[NSString stringWithString:@"Content-Type: application/octet-stream\r\n\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:Filedata];
[body appendData:[[NSString stringWithFormat:@"\r\n--%@--\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]];
[request setHTTPBody:body];
NSURLConnection *theConnection=[[NSURLConnection alloc] initWithRequest:request delegate:self];
if (theConnection)
mutaebleData = [[NSMutableData data] retain];
else
NSLog(@"No Connection");
使用此委托上载数据状态,但无济于事
- (void)request:(NSURLConnection *)request
didSendBodyData:(NSInteger)bytesWritten totalBytesWritten:(NSInteger)totalBytesWritten totalBytesExpectedToWrite:(NSInteger)totalBytesExpectedToWrite
{
NSLog(@"%d bytes out of %d sent.", totalBytesWritten, totalBytesExpectedToWrite);
}
请看一下这个线程,它将帮助您:
这是适合您的最佳自定义控制器。
您可以从此链接中找到它的Custom UIActivityIndicator
https://github.com/jdg/MBProgressHUD
这些不是苹果特有的控件。 此MBProgressHUD控件由下面介绍的三个控件组成。
UIImageView
。 UIActivityIndicatory
UILabel
以及要显示的任何消息。 MBProgressHUD
是iOS的一个MBProgressHUD
类,在后台线程中工作时显示带有指示器和/或标签的半透明HUD。 HUD的目的是通过一些附加功能来替代未记录的私有UIKit UIProgressHUD。......
有关更多信息,请访问上面的链接
您可以最简单地提醒UIProgressView,并且可以通过int委托来设置progress的值,例如:
- (void)request:(NSURLConnection *)request
didSendBodyData:(NSInteger)bytesWritten totalBytesWritten:(NSInteger)totalBytesWritten totalBytesExpectedToWrite:(NSInteger)totalBytesExpectedToWrite
{
NSLog(@"%d bytes out of %d sent.", totalBytesWritten, totalBytesExpectedToWrite);
UIProgressView *progressView = [[UIProgressView alloc] initWithProgressViewStyle:UIProgressViewStyleDefault];
[self.view addSubview:progressView];
progressView.progress = (double) bytesWritten / totalBytesWritten;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.