0

私はこのコードを持っています:

[self performSelector:@selector(animationWithType:) withObject:PasscodeAnimationTypeConfirm afterDelay:0.2];

このメソッドに:

-(void)animationWithType:(PasscodeAnimationType)type;

これをその場所に置く:

[self performSelector:@selector(animationWithType:) withObject:[NSNumber numberWithInt:PasscodeAnimationTypeConfirm] afterDelay:0.2];

私のメソッドは PasscodeAnimationTypeConfirm と同じ値として分類されない「1」の NSLog を返します。どうすればこれを修正できますか?

4

2 に答える 2

2

ええ、私の知る限り、型 (int、chars など) ではなく、オブジェクトをパラメーターとして使用して performSelector:blahBlah:withDelay: のみを実行できます。

次のように、役立つ別の関数を作成できます。

-(void)animationWithNumber:(NSNumber)type{
    [self animationWithType:[NSNumber intValue]];
}

そして、投稿したコードからこれを使用します:

[self performSelector:@selector(animationWithType:) withObject:[NSNumber numberWithInt:PasscodeAnimationTypeConfirm] afterDelay:0.2];
于 2011-07-30T15:34:03.247 に答える
1

@Emilio: performSelector 呼び出しで新しいメソッドを呼び出すべきではありませんか?

[self performSelector:@selector(animationWithNumber:) withObject:[NSNumber numberWithInt:PasscodeAnimationTypeConfirm] afterDelay:0.2];

これは、この概念のより詳細な使用法を示す私の例です。

http://kerkermeister.net/objective-c-adapter-from-nsinteger-to-id-when-using-performselector-withobject/

アダプターは次のようになり、さらにいくつかのチェックを実行します。

-(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];
    }
}
于 2013-09-17T19:08:18.397 に答える