1

So I have a PanelController which is a NSWindowController, and it instantiates an object called FileUploader. But inside of FileUploader, I want to be able to update some text on the Panel informing the user of the progress that has been made so far. But I don't know how to reference PanelController given that I can't instantiate a new one.

Am I supposed to use ApplicationDelegate as the go-between, and if so how do I reference that? If so, do I need ApplicationDelegate to instantiate both PanelController and FileUploader, but then I still don't understand how to reference the ApplicationDelegate.

bryanmac
  • 38,941
  • 11
  • 91
  • 99
Jeremy Smith
  • 14,727
  • 19
  • 67
  • 114

2 Answers2

3

Apple recommends using Delegates in such scenarios.

Here are some SO answers on how to make delegates:

  1. How Do I Create Delegates in Obj-C
  2. How Does Delegate Work in Obj-C
Community
  • 1
  • 1
mohdajami
  • 9,604
  • 3
  • 32
  • 53
3

Also consider using blocks which is another more modern apple approach to callbacks. Apple is using it more and more in their new APIs.

Here's a specific SO on updating UI and also making it async:

GCD, Threads, Program Flow and UI Updating

Here's another SO article on blocks & delegates as callbacks

How to simplify callback logic with a Block?

Community
  • 1
  • 1
bryanmac
  • 38,941
  • 11
  • 91
  • 99