1

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?

neebz
  • 11,465
  • 7
  • 47
  • 64

1 Answers1

3

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.

Jim
  • 72,985
  • 14
  • 101
  • 108
  • Thanks Jim. That doesn't serve the purpose because I am saving the download images record in database, So the view will reload itself anyways from the database when `viewDidLoad` is called. What I want was is that as images are downloaded, if user is in first view: count should be updated or if user is in second view: thumbnails are added seamlessly. – neebz Dec 12 '11 at 21:20
  • this looks like my answer : http://stackoverflow.com/questions/5873450/calling-method-in-current-view-controller-from-app-delegate-in-ios – neebz Dec 12 '11 at 21:23
  • Yes, I understood the problem. I don't think you understood the solution I proposed. Did you notice that the accepted answer for the question you link to uses `NSNotificationCenter` like I suggested? – Jim Dec 12 '11 at 21:27