NSInvocationを初めて使用しようとしていますが、stackoverflowで他の回答コードから以下のコードが採用されています。
タイマーは正常に動作しますが、実際に期限切れになり、(animationEnd:)でコードを実行するとクラッシュします。
UIImageView* animationView = [animationViewArray objectAtIndex: i];
[self.imageView addSubview: animationView];
[animationView startAnimating];
// [NSTimer scheduledTimerWithTimeInterval: 5.5 target: self selector: @selector(animationEnd:) userInfo: animationView repeats: NO];
SEL selector = @selector(animationEnd:);
NSMethodSignature *signature = [self methodSignatureForSelector:selector];
NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:signature];
[invocation setSelector:selector];
//The invocation object must retain its arguments
// when passing to timer, it's ok
// [animationView retain];
//Set the arguments
[invocation setTarget:self];
[invocation setArgument:&animationView atIndex:2];
[NSTimer scheduledTimerWithTimeInterval:0.1 invocation:invocation repeats:NO];
-(void) animationEnd:(NSInvocation*) invocation
{
UIImageView* animationView = nil;
[invocation getArgument:&animationView atIndex:2];
[animationView removeFromSuperview];
[animationView release];
}
どこでめちゃくちゃになりましたか?
クラッシュログに基づくと、(animationEnd :)での呼び出しは、呼び出しに渡した引数自体のように見えます。
紛らわしいstuf..
ありがとうございました。