[英]Upload a file to server to show UIProgressView in iPhone?
I have upload a file through my server and its working fine, but i want to show a progressview for upload status, How to do this, Please help me 我已经通过服务器上传了文件,并且文件可以正常工作,但是我想显示一个进度视图以查看上传状态,如何执行此操作,请帮帮我
Thanks in Advance 提前致谢
I tried this: 我尝试了这个:
[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");
Using this delegate to Upload data status, but it wont help 使用此委托上载数据状态,但无济于事
- (void)request:(NSURLConnection *)request
didSendBodyData:(NSInteger)bytesWritten totalBytesWritten:(NSInteger)totalBytesWritten totalBytesExpectedToWrite:(NSInteger)totalBytesExpectedToWrite
{
NSLog(@"%d bytes out of %d sent.", totalBytesWritten, totalBytesExpectedToWrite);
}
Please have a look at this thread,It will help you: 请看一下这个线程,它将帮助您:
How to track the progress of a download using ASIHTTPRequest (ASYNC) 如何使用ASIHTTPRequest(ASYNC)跟踪下载进度
This is the Best Custom controller for you. 这是适合您的最佳自定义控制器。
It Custom UIActivityIndicator
that you can found from this link 您可以从此链接中找到它的Custom
UIActivityIndicator
https://github.com/jdg/MBProgressHUD https://github.com/jdg/MBProgressHUD
These is not apple specific controls. 这些不是苹果特有的控件。 This MBProgressHUD controls consist of Three controls that describe in below.
此MBProgressHUD控件由下面介绍的三个控件组成。
UIImageView
with the image. UIImageView
。 UIActivityIndicatory
UILabel
with whatever message you want to display. UILabel
以及要显示的任何消息。 MBProgressHUD
is an iOS drop-in class that displays a translucent HUD with an indicator and/or labels while work is being done in a background thread. MBProgressHUD
是iOS的一个MBProgressHUD
类,在后台线程中工作时显示带有指示器和/或标签的半透明HUD。 The HUD is meant as a replacement for the undocumented, private UIKit UIProgressHUD with some additional features....... HUD的目的是通过一些附加功能来替代未记录的私有UIKit UIProgressHUD。......
For mor information go to above Link 有关更多信息,请访问上面的链接
The simplest you can alert a UIProgressView and int the delegate you can set the value of progress for example: 您可以最简单地提醒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.