Iphone Performselector-参数2从整数生成指针而不强制转换
我有以下代码:Iphone Performselector-参数2从整数生成指针而不强制转换,iphone,objective-c,performselector,Iphone,Objective C,Performselector,我有以下代码: [self performSelector:@selector(animationWithType:) withObject:PasscodeAnimationTypeConfirm afterDelay:0.2]; 对于此方法: -(void)animationWithType:(PasscodeAnimationType)type; 把这个放在它的位置上: [self performSelector:@selector(animationWithType:) withOb
[self performSelector:@selector(animationWithType:) withObject:PasscodeAnimationTypeConfirm afterDelay:0.2];
对于此方法:
-(void)animationWithType:(PasscodeAnimationType)type;
把这个放在它的位置上:
[self performSelector:@selector(animationWithType:) withObject:[NSNumber numberWithInt:PasscodeAnimationTypeConfirm] afterDelay:0.2];
返回一个NSLog为“1”,我的方法不会将其归类为与PasscodeAnimationTypeConfirm相同的值。如何解决这个问题?是的,据我所知,您只能使用performSelector:blahBlah:withDelay:将对象作为参数,而不是类型(int、chars等) 您可以创建另一个函数来帮助您,如下所示:
-(void)animationWithNumber:(NSNumber)type{
[self animationWithType:[NSNumber intValue]];
}
使用你发布的代码中的这个:
[self performSelector:@selector(animationWithType:) withObject:[NSNumber numberWithInt:PasscodeAnimationTypeConfirm] afterDelay:0.2];
是的,据我所知,您只能使用performSelector:blahBlah:withDelay:将对象作为参数,而不是类型(int、chars等) 您可以创建另一个函数来帮助您,如下所示:
-(void)animationWithNumber:(NSNumber)type{
[self animationWithType:[NSNumber intValue]];
}
使用你发布的代码中的这个:
[self performSelector:@selector(animationWithType:) withObject:[NSNumber numberWithInt:PasscodeAnimationTypeConfirm] afterDelay:0.2];
@Emilio:你的performSelector调用不应该调用你的新方法吗
[self performSelector:@selector(animationWithNumber:) withObject:[NSNumber numberWithInt:PasscodeAnimationTypeConfirm] afterDelay:0.2];
这是我的一个例子,展示了这个概念的更详细的使用
适配器如下所示,并执行更多检查:
-(void)animationWithNumber:(id)_animationType {
if ([_animationType respondsToSelector:@selector(intValue)]) {
int _t = [_animationType intValue];
switch (_t) {
case AnimationType1:
_t = AnimationType1;
break;
case AnimationType2:
_t = AnimationType2;
break;
default:
_t = AnimationTypeUndefined;
break;
}
[self animationWithType:_t];
}
}
@Emilio:你的performSelector调用不应该调用你的新方法吗
[self performSelector:@selector(animationWithNumber:) withObject:[NSNumber numberWithInt:PasscodeAnimationTypeConfirm] afterDelay:0.2];
这是我的一个例子,展示了这个概念的更详细的使用
适配器如下所示,并执行更多检查:
-(void)animationWithNumber:(id)_animationType {
if ([_animationType respondsToSelector:@selector(intValue)]) {
int _t = [_animationType intValue];
switch (_t) {
case AnimationType1:
_t = AnimationType1;
break;
case AnimationType2:
_t = AnimationType2;
break;
default:
_t = AnimationTypeUndefined;
break;
}
[self animationWithType:_t];
}
}
这与您的问题无关,但命名约定建议animationWithType:将返回给定类型的动画。我建议您改为PerformManizationWithType:。我一直在忙着删除尽可能多的performSelector实例,并将其替换为块。这与您的问题无关,但命名约定建议animationWithType:将返回给定类型的动画。我建议您改为PerformManizationWithType:。我一直在忙着删除尽可能多的performSelector实例,并将其替换为块。更好的方法是使用NSInvocation,因为您不需要创建新方法,仅针对这种情况。更好的方法是使用NSInvocation,因为您不需要创建一个新方法,仅针对这种情况。