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