J'ai une minuterie appeler une méthode, mais cette méthode prend un paramether:Comment passer un argument à une méthode appelée dans un NSTimer
theTimer = [NSTimer scheduledTimerWithTimeInterval:animationInterval target:self selector:@selector(timer) userInfo:nil repeats:YES];
devrait être
theTimer = [NSTimer scheduledTimerWithTimeInterval:animationInterval target:self selector:@selector(timer:game) userInfo:nil repeats:YES];
maintenant cette syntaxe n » Cela semble être juste. J'ai essayé avec NSInvocation mais j'ai eu quelques problèmes:
timerInvocation = [NSInvocation invocationWithMethodSignature:
[self methodSignatureForSelector:@selector(timer:game)]];
theTimer = [NSTimer scheduledTimerWithTimeInterval:animationInterval
invocation:timerInvocation
repeats:YES];
Comment devrais-je utiliser l'Invocation?
Si vous devez passer plusieurs objets, c'est le chemin à parcourir. Mais si c'est juste un seul objet, vous n'avez pas besoin de l'encapsuler dans un dictionnaire. – DarkDust
True. Je viens de voir les notifications utiliser les dictionnaires userInfo afin de garder la cohérence. – Eimantas