2010-12-29 8 views
0
내가 처음있는 NSInvocation를 사용하기 위해 노력하고있어

은, 아래의 코드는 유래에서 다른 응답 코드에서 채택된다.
타이머는 잘 실행하지만, 실제로 만료 될 때 충돌과 (animationEnd :)에서 코드를 실행(아이폰)있는 NSInvocation 충돌 문제

I 난장판을했다
 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 ..

감사합니다.

답변

1

는 animationView를 해제하지 마십시오. 당신은 결코 그것을 간직하지 않았습니다. 기본적으로,이 코드를 제공, 우리는 그것을 소유 할 수있는 세 사람을 참조하십시오 (이 사라질 때 소유권을 포기합니다) 호출, animationViewArray (뷰가에서 제거됩니다 때 소유권을 포기 누가), 그리고 animationView의 수퍼라는 이름의 배열을 (removeFromSuperview로 전화하면 즉시 소유권을 포기합니다).

당신이이 하나도 없기 때문에, 당신이 그것을 해제하지 않아야합니다.