我如何知道哪个 ViewController 处于活动状态?

发布于 2024-12-21 08:13:33 字数 283 浏览 3 评论 0原文

我正在使用 NSOperationQueue 下载图像。

我想在图像下载完成后调用视图控制器的方法reloadView

但是,当下载正在进行时,用户很可能已移至不同的视图。这个另一个视图还将有一个 reloadView 方法(例如,第一个视图显示下载图像总数,第二个视图显示下载图像的缩略图)

基本上我想要的是,每当图像下载完成时,我应该能够调用活动视图控制器的 reloadView 方法吗?

这怎么可能?

I am downloading images using NSOperationQueue.

I want to call a method reloadView of my view controller once the image download is complete.

However when the download is in progress, it is fairly possible that user has moved to a different view. This other view will also have a reloadView method (e.g. first view shows total downloaded images count, and second shows thumbnails of download images)

Basically what I want is that whenever an image download is completed, I should be able to call the reloadView method of the active view controller whichever it is?

How can this be possible?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

暗地喜欢 2024-12-28 08:13:33

我不会采取这种方法。这就是 NSNotificationCenter 的设计目的。图片下载完成后,发布通知。在需要了解它的视图控制器中,在 viewDidAppear: 中监听通知并在 viewDidDisappear: 中停止监听。您的下载代码不需要知道视图控制器的详细信息或其状态。

I wouldn't take that approach. This is the kind of thing NSNotificationCenter is designed for. When your image has finished downloading, post a notification. In view controllers that need to know about it, listen for the notification in viewDidAppear: and stop listening in viewDidDisappear:. Your downloading code doesn't need to know the details of your view controllers or their status.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文