在一个块中调用一个方法? [英] call a method in a block?

查看:84
本文介绍了在一个块中调用一个方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是ARC的新手.我想在一个完整的块中调用一个方法,但得到警告:在此块中强烈捕获自身"可能会导致保留周期..代码:

I'm new to ARC. I want to call a method in a complete block, but I get the warning: Capturing 'self' strongly in this block is likely to lead to a retain cycle.. Code:

- (void) handlerComplete
{
    //...
}

- (void) loadData
{
    ...
    operation.completeBlock = ^(NSInteger index) {
        [self handlerComplete];
    };
}

有什么建议吗?谢谢.

推荐答案

尝试使用

- (void) loadData
{
    __weak MyClassType *myClass = self;
    operation.completeBlock = ^(NSInteger index) {
        [myClass handlerComplete];
    };
}

这篇关于在一个块中调用一个方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆