在iPhone中调用类的SEL(选择器)?

时间:2012-01-31 06:07:11

标签: ios iphone selector

我有一个类,我在其中调用另一个类的方法(带有SEL参数),如下所示

// class 1

+(CCScene *) scene
{
// 'scene' is an autorelease object.
CCScene *scene = [CCScene node];

// 'layer' is an autorelease object.
HelloWorldLayer *layer = [HelloWorldLayer node];

// add layer as a child to scene 
[scene addChild: layer];

// returns a CClayer Object
id myClassLayer = [myClass objWithBackgroundSprite:objBackground withRect:CGRectMake(160,100, 300,120) atPoistion:pos_Top];

SEL callOnClick;
[myClassLayer AddButtonWithImage:ButtonBackground selector:callOnClick withDisabledImage:disabledBackground];

[scene addChild: myClassLayer];

// return the scene
return scene;
}

// class 2

-(void)AddButtonToHUDWithImage:(NSString *)imageName selector:(SEL)selector withDisabledImage:(NSString *)disbdImageName

{

CCMenuItem *menuItem1 = [CCMenuItemImage itemFromNormalImage:imageName selectedImage:imageName disabledImage:disbdImageName target:self selector:@selector(selector)];

CCMenu *menu = [CCMenu menuWithItems:menuItem1,nil];  
[menu setPosition:ccp(160,100)];
[self addChild:menu];
}

-(void)selector
{
    // not creating any object .. some other way if possible
}

但我想在HelloWorld中声明选择器方法(callOnClick)(myClass是一个通用类)。

我如何才能在HelloWorld中调用选择器?

1 个答案:

答案 0 :(得分:0)

如果您不需要实例,那么您可以使用类方法,目标/对象将是[SOMEType class][self class]

+ (void)selector // <<    + not -
{
    // not creating any object .. some other way if possible
}