我如何知道哪个 ViewController 处于活动状态?
我正在使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不会采取这种方法。这就是
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 inviewDidAppear:
and stop listening inviewDidDisappear:
. Your downloading code doesn't need to know the details of your view controllers or their status.