PDA

View Full Version : Setting up a custom class with a delegate




RossOliver
Jun 25, 2008, 01:01 PM
Hey,

What I need is for a class of my own, say MyClass, to be able to send messages to a class that uses it, say MyOtherClass. For instance, if MyClass is running a variable length timer and when the timer expires it needs to notify MyOtherClass to handle it, how would I go about setting up the required relationship?

I'm sure there is an article somewhere on what I need and I would be grateful if someone could point me to one if they know of any, or try and give me a breif explanation of the steps I need to take...

Cheers,

-Ross



Enuratique
Jun 25, 2008, 04:37 PM
Hey,

What I need is for a class of my own, say MyClass, to be able to send messages to a class that uses it, say MyOtherClass. For instance, if MyClass is running a variable length timer and when the timer expires it needs to notify MyOtherClass to handle it, how would I go about setting up the required relationship?

I'm sure there is an article somewhere on what I need and I would be grateful if someone could point me to one if they know of any, or try and give me a breif explanation of the steps I need to take...

Cheers,

-Ross

I'm assuming you've got some programming experience based on this question. Languages like Java and C# require you to attach listeners to objects that have events, a form of loose coupling.

This article (http://developer.apple.com/documentation/Cocoa/Conceptual/CocoaFundamentals/CommunicatingWithObjects/chapter_6_section_1.html) on Apple's developer site should be pretty useful to you.

RossOliver
Jun 29, 2008, 10:32 AM
I'm assuming you've got some programming experience based on this question. Languages like Java and C# require you to attach listeners to objects that have events, a form of loose coupling.

This article (http://developer.apple.com/documentation/Cocoa/Conceptual/CocoaFundamentals/CommunicatingWithObjects/chapter_6_section_1.html) on Apple's developer site should be pretty useful to you.

Just what I was after, cheers :)

I have another question which I may as well ask in here instead of starting a new thread...

In my AppDelegate class I open a connection to an sqlite database, with a reference to the database stored as an instance variable (accessible via a get method).

I need to get at this reference in my main view controller. My main view is loaded automatically, though (with [window makeKeyAndVisible] and the nib specified in a plist). How do I go about calling a custom init method in my main view controller which will allow me to pass the database reference in:

initWithDatabase: ( sqlite3 * )database;

Thanks for your time,

-Ross