Я пытаюсь использовать NSInvocation в первый раз, код ниже принят из других кодов ответов в stackoverflow.
Таймер работает нормально, но он выходит из строя, когда он на самом деле истекает, и выполняет код в (animationEnd :)(iphone) nsInvocation crash question
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 ..
спасибо.