首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >(iphone) nsInvocation崩溃问题

(iphone) nsInvocation崩溃问题
EN

Stack Overflow用户
提问于 2010-12-29 18:24:09
回答 1查看 326关注 0票数 0

我是第一次尝试使用NSInvocation,下面的代码是从stackoverflow的其他答案代码中采用的。

计时器运行良好,但是当它实际超时并在(animationEnd:)上执行代码时就会崩溃。

代码语言:javascript
复制
        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..

谢谢。

EN

回答 1

Stack Overflow用户

发布于 2010-12-29 18:32:52

不要释放animationView。你从来没有保留过它。基本上,给定这段代码,我们看到可能拥有它的三个人:调用(当它消失时将放弃所有权),名为animationViewArray的数组(当视图从其中移除时将放弃所有权),以及动画视图的superview (当您调用removeFromSuperview时立即放弃所有权)。

既然你不是这些,你就不应该发布它。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/4553270

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档