gpt4 book ai didi

iphone - 如何将 3 个参数传递给@selector

转载 作者:可可西里 更新时间:2023-11-01 06:19:47 25 4
gpt4 key购买 nike

我在

中创建了一个 Action
-(void) ccTouchEnded:(UITouch *)touch withEvent:(UIEvent *)event

就像这样:

self.moveAction = [CCSequence actions:                          
[CCMoveTo actionWithDuration:moveDuration position:touchLocation],
[CCCallFunc actionWithTarget:self selector:@selector(guyMoveEnded)],
nil
];

但是现在,我想通过@selector 自动调用以下方法:

-(void)guyMoveEnded:(BOOL)flag AndWhere:(CGPoint)where Andtime:(float)time{
//do something...
}

我该怎么做?请帮助我,我对选择器感到困惑。

谢谢!

最佳答案

您可以将您的参数添加到 NSArray 中,然后将其作为参数提供给您的选择器:

NSArray *params = [NSArray arrayWithObjects:@"a str", [NSNumber numberWithInt:42],myObj];
[self performSelector:@selector(myMethod:)withObject:params];

然后在你的方法中解压参数:

-(void)myMethode:(NSArray*)params
{
NSString *strArg = [params objectAtIndex:0];
NSNumber * numVal = [params objectAtIndex:1];
NSObject *objArg = [params objectAtIndex:2];
int intArg = [numVal intValue];
.
.
.
}

关于iphone - 如何将 3 个参数传递给@selector,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11683173/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com