[英]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.