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

标签 iphone objective-c ios

我在

中创建了一个 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/

相关文章:

ios - 由于未捕获的异常 'Texture Atlas Not Found' 而终止应用程序

ios - 如何调整 Xcode (Storyboard) 中所有屏幕的 View ?

ios - 以编程方式将 Sqlite 表数据导出到 csv 文件

objective-c - 什么更有效率 : loading and adding a nib or creating the custom controls programmatically?

objective-c - 将 NSData append 到 Objective C 中的文件

iphone - 在数组中搜索相似的拼写单词/对象

iphone - 未通过 Graph API 接收 Facebook 图片

ios - 将 iOS 键盘上的 "Done"按钮翻译成其他语言

iphone - AdMob (iOS) 上的实现

iphone - 如何恢复消耗品应用内购买?