简体   繁体   English

swift 如何在多个 ViewController 中查看 downloadTask 的进度

[英]swift How to view progress of downloadTask in several ViewControllers

I have two viewControllers VCList(CollectionView with items) VCDetails by selecting item from VCList it opens VCDetails, on VCDetails I have button download that starts downloading huge file according selected item with showing its progress, by dismissing VCDetails I want to show progress on VCDetails, and on entering again on that VCDetails if its is still downloading I want to show continued progress of downloading.我有两个viewControllers VCList(CollectionView with items)VCDetails,通过从VCList中选择项目它打开VCDetails,在VCDetails我有按钮下载,根据所选项目开始下载大文件并显示其进度,通过关闭VCDetails我想在VCDetails上显示进度,如果它仍在下载,则再次输入该 VCDetails 时,我想显示下载的持续进度。 Please any suggestions on how to achieve this?请就如何实现这一目标提出任何建议? Thanks a lot非常感谢

This sounds like a loosely coupled notification.这听起来像是一个松散耦合的通知。 I would suggest having your download process broadcast Notification messages to the main thread at modest intervals (every few seconds).我建议让您的下载过程以适当的间隔(每隔几秒)将Notification消息广播到主线程。 Then have the current view controller subscribe to those notifications and use them to update a download progress indicator.然后让当前视图 controller 订阅这些通知并使用它们来更新下载进度指示器。

Better yet, create a reusable download progress indicator that takes a download ID and listens for progress updates.更好的是,创建一个可重复使用的下载进度指示器,该指示器采用下载 ID 并侦听进度更新。 Have your download manager return a unique download ID, and pass that to the view controllers that need to display progress.让您的下载管理器返回一个唯一的下载 ID,并将其传递给需要显示进度的视图控制器。 Have the view controllers install the download ID into their reusable download indicators views.让视图控制器将下载 ID 安装到其可重复使用的下载指示器视图中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在iOS Swift中向多个ViewController添加通用视图? - How can I add a common view to multiple ViewControllers in iOS Swift? 如何在 Swift 中使用 NSURLSession downloadTask 顺序下载多个文件 - How To Download Multiple Files Sequentially using NSURLSession downloadTask in Swift 如何解决Swift 4中的内存循环URLSession.downloadTask? - How to resolve memory cycle in Swift 4 URLSession.downloadTask? Swift:如何在后台URLSession.downloadTask上捕获磁盘已满错误? - Swift: How to catch disk full error on background URLSession.downloadTask? 如何更新另一个UIViewController-SWIFT上的进度视图? - How to update a progress view that is on another UIViewController - SWIFT? 如何在moya swift中添加进度视图? - how to add progress view in moya swift? 进度视图未更新 - Swift - Progress view is not updating - Swift Swift 4如何在ViewControllers和ContainerViews之间传递数据? - Swift 4 How to pass data between ViewControllers and ContainerViews? 如何从 Swift 中的 UITabBarController 中删除多个视图控制器 - How to remove multiple viewcontrollers from UITabBarController in Swift 如何在Swift中的多个ViewController之间共享数据 - how to share data between many ViewControllers in Swift
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM