我有一個計時器調用一個方法,但這種方法需要一個paramether方法:如何將參數傳遞給一個名爲在的NSTimer
theTimer = [NSTimer scheduledTimerWithTimeInterval:animationInterval target:self selector:@selector(timer) userInfo:nil repeats:YES];
應該
theTimer = [NSTimer scheduledTimerWithTimeInterval:animationInterval target:self selector:@selector(timer:game) userInfo:nil repeats:YES];
現在這個語法沒有按」 t似乎是正確的。我試着用NSInvocation的,但我得到了一些問題:
timerInvocation = [NSInvocation invocationWithMethodSignature:
[self methodSignatureForSelector:@selector(timer:game)]];
theTimer = [NSTimer scheduledTimerWithTimeInterval:animationInterval
invocation:timerInvocation
repeats:YES];
我應該如何使用調用?
如果您需要傳遞幾個對象,那就是要走的路。但如果它只是一個單一的對象,你不需要將它封裝到字典中。 – DarkDust 2011-03-02 10:45:15
是的。我剛剛看到通知使用userInfo字典,所以認爲保持一致性。 – Eimantas 2011-03-02 10:58:32