开发者

Question about instantiating object

开发者 https://www.devze.com 2023-03-23 04:39 出处:网络
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 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消