加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

objective-c – Swift中的块显示错误“调用中缺少参数#2的参数”

发布时间:2020-12-16 09:56:35 所属栏目:百科 来源:网络整理
导读:我现在在我的项目中使用Jonas Gessner的 JGActionSheet与Swift,并且示例是由Objective-C编写的,当我尝试将块转换为Swift时,Xcode显示错误“在调用中缺少参数#2的参数”,这里是我写的代码和截图: Objective-C样本 JGActionSheet *sheet = [JGActionSheet act
我现在在我的项目中使用Jonas Gessner的 JGActionSheet与Swift,并且示例是由Objective-C编写的,当我尝试将块转换为Swift时,Xcode显示错误“在调用中缺少参数#2的参数”,这里是我写的代码和截图:

Objective-C样本

JGActionSheet *sheet = [JGActionSheet actionSheetWithSections:sections];
[sheet setButtonPressedBlock:^(JGActionSheet *sheet,NSIndexPath *indexPath) 
{
    [sheet dismissAnimated:YES];
}];

我用Swift编写的代码

let actionSheet = JGActionSheet(sections: sections)
actionSheet.buttonPressedBlock {
    (sheet: JGActionSheet!,indexPath: NSIndexPath!) in
    actionSheet.dismissAnimated(true)
}

错误截图

Missing argument for parameter #2 in call

所以请帮我解决这个问题,非常感谢!

解决方法

actionSheet.buttonPressedBlock是一个属性.你正试图设置它.那你的等号在哪里?这就是你在Swift中设置的方法:

myThing.myProperty = myValue

您尝试将此属性设置为块(函数)的事实不会改变任何内容.所以:

let actionSheet = JGActionSheet(sections: sections)
actionSheet.buttonPressedBlock = {
    (sheet: JGActionSheet!,indexPath: NSIndexPath!) in
    actionSheet.dismissAnimated(true)
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读