提问人:Arthur 提问时间:6/8/2021 更新时间:6/8/2021 访问量:144
在快速弱自我中调用目标 C 块总是零
Calling Objective C block in swift weak self always nill
问:
我在 Objective C .h 文件中有一个块属性 我正在使用此代码在 swift 文件中创建目标 C 控制器的变量
let viewController = ViewController(nibName: "ViewController", bundle: nil)
viewController.onCellPressed = { [weak self] cellModel in
guard let cellModel = cellModel else { return }
self?.openDetails(cellModel)
}
这是区块 var 的声明
@property (nonatomic, copy) void (^onCellPressed)(CellModel* model);
我正在用这段代码运行这个块
self.onCellPressed([_photos objectAtIndex:indexPath.row]);
问题是里面[weak self]
{ [weak self] cellModel in
guard let cellModel = cellModel else { return }
self?.openDetails(cellModel)
}
总是nil
如何在 swift 文件中的块内使用弱自我?
答: 暂无答案
评论
viewController