Question about instantiating object
I am new to Objective C and Cocoa. Really don't like the syntax as I'm from Java and C#. I'm trying to do something simple and I get the following error:
I import this in using
#import "Defaults.h"
-(void) awakeFromNib{
Defaults *theDefaults = [[Defaults alloc] init];
}
-(IBAction) addPlanets:(id)sender{
[theDefaults setValue:[planetsButton titleOfSelectedItem] forKey:@"planets"];
NSLog([planetsButton titleOfSelectedItem]);
}
The erro开发者_JS百科r I get is
Unknown Receiver theDefaults; Did you mean "Defaults"?
Can someone help me on what this is?
theDefaults
doesn't exist in the scope of addPlanets:
. You need to make it a global or an instance variable, rather than creating it in awakeFromNib
and immediately leaking it.
精彩评论