neeebzz
neeebzz

Reputation: 11538

How can I know which ViewController is active?

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?

Upvotes: 1

Views: 861

Answers (1)

Jim
Jim

Reputation: 73946

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.

Upvotes: 3

Related Questions