• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Two controllers in a window, how do I get one to run a function in another?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Two controllers in a window, how do I get one to run a function in another?


  • Subject: Re: Two controllers in a window, how do I get one to run a function in another?
  • From: BareFeet <email@hidden>
  • Date: Tue, 1 Sep 2009 17:34:29 +1000

Hi Graham,

To try to isolate the issue, I created a "Refresh" button and hooked it up to a refresh method in MyController. It just calls "init" (as below). When the program runs and instantiates a document that I open, debugging the init call shows the_document as nil. But when I click "Refresh" to call init again, it shows the_document as not nil and fileString is assigned correctly etc.

So perhaps it's a problem with the instantiation?

The ivar <the_document> won't be valid until at least -awakeFromNib is called. That's the earliest point you can access it.

That did the trick. I moved the code (referring to the_document) to run after/in awakeFromNib, rather than in the init method.


I think you're over-thinking this. Is MyController an object in the nib?

Yes.

If so, connect <the_document> to File's Owner and you're done.

Already done.

By the time your document is ready to use, the controller will be valid, exist, and be working.

It is working now.

Init time for any of these objects is too early - debugging in there won't tell you much because at that time the nib hasn't been fully loaded so none of the outlets will have been set.

That was the problem.

If on the other hand you're instantiating MyController in code

Nah, wasn't over-thinking ;-)

Thanks a lot Graham for your time and patience. I really appreciate it. As I mentioned, this has been one repeating gap in my knowledge (accessing one object's ivars or methods from another in the same nib). I had seen the IBOutlet approach mentioned in forums, but nothing really laid it out.

Tom
BareFeet

_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Prev by Date: Re: What sound plays after an Installer runs?
  • Next by Date: Re: "Format not a string literal and no format arguments"
  • Previous by thread: Re: Two controllers in a window, how do I get one to run a function in another?
  • Next by thread: Re: New Developer Docs for Cocoa and QTKit Developers with Snow Leopard Release
  • Index(es):
    • Date
    • Thread