问题
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