我现在正在项目中使用Jonas Gessner的JGActionSheet和Swift,示例是由Objective-C编写的,当我尝试将块转换为Swift时,Xcode显示错误“参数缺少参数#2在电话中“,这是我写的代码和屏幕截图:
JGActionSheet *sheet = [JGActionSheet actionSheetWithSections:sections];
[sheet setButtonPressedBlock:^(JGActionSheet *sheet, NSIndexPath *indexPath)
{
[sheet dismissAnimated:YES];
}];
let actionSheet = JGActionSheet(sections: sections)
actionSheet.buttonPressedBlock {
(sheet: JGActionSheet!, indexPath: NSIndexPath!) in
actionSheet.dismissAnimated(true)
}
Missing argument for parameter #2 in call
所以请帮我解决这个问题并非常感谢!
答案 0 :(得分:7)
actionSheet.buttonPressedBlock
是属性。您正在尝试设置它。那你的等号在哪里?这就是你在Swift中设置的方法:
myThing.myProperty = myValue
您尝试将此属性设置为块(函数)的事实不会改变任何内容。所以:
let actionSheet = JGActionSheet(sections: sections)
actionSheet.buttonPressedBlock = {
(sheet: JGActionSheet!, indexPath: NSIndexPath!) in
actionSheet.dismissAnimated(true)
}