Re: Using a String Object in another class
Re: Using a String Object in another class
- Subject: Re: Using a String Object in another class
- From: Nick Zitzmann <email@hidden>
- Date: Sun, 21 Sep 2003 13:29:09 -0700
On Sunday, September 21, 2003, at 04:57 AM, Kay Lvhmann wrote:
In the AppController Class i create a NSString object, which contains
Data from TextFile. Now i would like to use this String to fill a
NSMutableArray in
the NSTableViewDelegate Class in order to fill the TableView with that
data.
I cannot get it to work. Now. How do i get this string into that other
class to work with it?
If there is only one instance of both the AppController and the
NSTableViewDelegate running, then you ought to make a singleton
accessor for NSTableViewDelegate so you can send messages to it from
AppController. You do that by doing something like this in your
NSTableViewDelegate source:
(note: written in Mail, untested, use at your own risk, I'm assuming
this "NSTableViewDelegate" class is instantiated in some nib loaded at
run time, etc.)
static NSTableViewDelegate *sharedDelegate;
@implementation NSTableViewDelegate
+ (NSTableViewDelegate *)sharedDelegate
{
if (sharedDelegate == nil)
{
// someone tried to access the shared object too early; raise
an exception here or something
}
return sharedDelegate;
}
- (id)init
{
// do the usual init stuff
sharedDelegate = self;
// continue the usual init stuff
}
// and so on, and so forth...
@end
Then you should be able to call [[NSTableViewDelegate sharedDelegate]
doSomething:someObject] to pass a "doSomething:" message & "someObject"
object to the delegate.
BTW, I don't think it's a very good idea to name your class
"NSTableViewDelegate", because Apple always starts every Cocoa class's
name with "NS". There might not be a current Cocoa class named
"NSTableViewDelegate", but if Apple adds one to a later version of
Cocoa, then your application will have some forward compatibility
issues...
Nick Zitzmann
AIM/iChat: dragonsdontsleep
Check out my software page:
http://seiryu.home.comcast.net/
"I have always wished that my computer would be as easy to use as my
telephone. My wish has come true. I no longer know how to use my
telephone." - Bjarne Stroustrup
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.