开发者社区 问答 正文

Capturing 'self' strongly in this block is likely to lead to a retain cycle

错误ID

ListViewController.m:135:10: Capturing 'self' strongly in this block is likely to lead to a retain cycle
开了ARC

[_tableView setPullToRefreshHandler:^{
    [self dataDidRefresh:nil];
}];

展开
收起
a123456678 2016-07-19 17:11:55 4081 分享 版权
2 条回答
写回答
取消 提交回答
  • 这是意味着有循环引用,建议在block外面声明__weak typeof(self) weakSelf = self; 然后在block里面使用weakSelf而不是self
    2019-07-17 19:58:36
    赞同 展开评论
  • 你把self转换一下加上block字段之后就不会被retain了

    __block ViewController *controller = self;
    [_tableView setPullToRefreshHandler:^{
    [controller dataDidRefresh:nil];
    }];

    2019-07-17 19:58:36
    赞同 展开评论
问答地址: