1

プログレスバーを使用して、ftpserver にアップロードされているファイルのアップロードの割合を表示しています。初めて、アップロードをキャンセルして、もう一度 id を開始すると、うまく更新されます。アップロード進行状況バーの 50% がいっぱいになり、3 回目は合計進行状況バーの 25% がいっぱいになります。

ここにコードがあります(サーバーにアップロードするためにs7ftpクラスを使用しています)

- (void)uploadBytesWritten:(S7FTPRequest *)request {


if (uploadedData < totalFileSize) {
    uploadedData = uploadedData + request.bytesWritten;
}
float total = (float)totalFileSize;
float bytes = (float)request.bytesWritten;
float pt = (bytes/total);
float totalSizeMb = (total/1048576);
//    NSLog(@"File Size in Mb:%f",totalSizeMb);
float uploadDataMb = (uploadedData/1048576);
NSString* totalSize = [NSString stringWithFormat: @"%5.1f", totalSizeMb];
NSString* uploadData = [NSString stringWithFormat: @"%5.1f", uploadDataMb];
//    float str = (uploadDataMb/totalSizeMb);
float str = (uploadedData/total);
float string = str*100;
int PercentageFinal = roundf(string);
 NSString *uploadPercentage = [NSString stringWithFormat:@"%d",PercentageFinal];
uploadpercentage = [NSString stringWithFormat:@"%@Mb/%@Mb", uploadData, totalSize];
NSLog(@"Uploading percentage:%@",uploadpercentage);
NSString *percentage = [NSString stringWithFormat:@"%f",pt];
uploadProgressView.progress += [percentage doubleValue];
[[NSNotificationCenter defaultCenter]   postNotificationName:@"UpdatePercentageNotification" object:nil userInfo:[[NSDictionary alloc] initWithObjectsAndKeys:percentage, @"percentage",uploadpercentage,@"UploadPercentage",uploadPercentage,@"Percent",nil]];

}

別のクラスで

-(void)Viewdidload{
      [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(updatePercentageNotificationOne:) name:@"UpdatePercentageNotification" object:nil];
  }

- (void)updatePercentageNotificationOne:(NSNotification *)notification{
NSLog(@"Updating percentage in upload all view");
 //    NSString *uploadpercentage = [[notification userInfo ]objectForKey:@"UploadPercentage"];
//    NSLog(@"Percentage:%@",uploadpercentage);
NSString *percent= [[notification userInfo]objectForKey:@"Percent"];
NSLog(@"percent:%@",percent);
NSString *percentage = [[notification userInfo] objectForKey:@"percentage"];
//    NSLog(@"Percentage......%@",percentage);
percentageLabel.text = percent;
ProgressBar.progress +=[percentage doubleValue];
[[NSNotificationCenter defaultCenter] removeObserver:@"UpdatePercentageNotification"];

 }
4

1 に答える 1

0

K アップロードを再開するときは、progressBar をリセットする必要があります。ユーザーがアップロードをクリックしたときに初期化を割り当てるだけです。

于 2013-05-16T10:38:42.630 に答える