我是新来Swift3。 我从我的应用程序上传视频到Amazon S3服务器和每个视频我已经设置一个进度视图。 当我添加视频到时候我ProgressView被更新,但我的问题是,当我准备从屏幕的背面和再来然后ProgressView没有更新。 我检查了使用断点,然后我的收藏查看cellForItemAt方法调用,但进展的观点并没有更新。 我一直在使用自定义添加细胞UIProgressView。
这里是我的代码:
public func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell{
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "videocell", for: indexPath) as! VideoCell
let videos = videoUrlsArr.object(at: indexPath.row) as! VideoModel
if videos.uploadProgress == 1.0{
cell.progressView.isHidden = true
}
else{
cell.progressView.isHidden = false
cell.progressView.setProgress(videos.uploadProgress, animated: true)
}
return cell
}
//上传视频文件到S3
func uploadMP4MediatoAmazonS3(videos: VideoModel, data:Data) {
let expression = AWSS3TransferUtilityUploadExpression()
expression.progressBlock = { (task: AWSS3TransferUtilityTask, progress: Progress) in
print(progress.fractionCompleted)
DispatchQueue.main.async(execute: {
self.progress = Float(progress.fractionCompleted)
videos.uploadProgress = self.progress
self.collectionView.reloadData()
self.collectionView.collectionViewLayout.invalidateLayout()
self.collectionView.layoutSubviews()
print("Progress: \(self.progress)")
})
}//progress expression....
self.uploadCompletionHandler = { (task, error) -> Void in
DispatchQueue.main.async(execute: {
if ((error) != nil){
print("Failed with error")
print("Error: %@",error!);
}
else if(self.progress != 1.0) {
print("Error: Failed - Likely due to invalid region / filename")
}
else{
videos.uploadProgress = 1
print("Success")
}
})
}//completion handler for upload....
let transferUtility = AWSS3TransferUtility.default()
transferUtility.uploadData(data, bucket: S3BucketName, key: videos.videoPath, contentType: "", expression: expression, completionHander: uploadCompletionHandler).continue ({ (task:AWSTask) -> Any? in
if let error = task.error {
print("Error: %@",error.localizedDescription);
}
if let exception = task.exception {
print("Exception: %@",exception.description);
}
if let _ = task.result {
print("Upload Started...")
}
return nil;
})
}
//我的自定义单元格级
import UIKit
class VideoCell: UICollectionViewCell {
@IBOutlet weak var videoImage: UIImageView!
@IBOutlet weak var playIcon: UIImageView!
@IBOutlet weak var deleteBtn: UIButton!
@IBOutlet weak var wbView: UIWebView!
@IBOutlet weak var progressView: UIProgressView!
}
请给我建议。 谢谢!