在iPhone中调用某个类的SEL(选择器)?
我有一个类,我在其中调用另一个类的方法(带有 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 中调用选择器?
I have a class in which i am calling a method(with a SEL parameter) of another class like as follows
// 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
}
but i would like to declare the selector method(callOnClick) in HelloWorld only(myClass being a Generic Class).
How can i call the selector in HelloWorld only??
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果不需要实例,则可以使用类方法,目标/对象将为
[SOMEType class]
或[self class]
:If you need no instance, then you can use a class method and the target/object will be
[SOMEType class]
or[self class]
: