How can I know which ViewController is active?

萝らか妹 提交于 2019-12-12 22:33:44

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/8480867/how-can-i-know-which-viewcontroller-is-active

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!