我现在在我的项目中使用jonas gessner'sJGActionSheet和swift,样本是由objective-c编写的,当我试图将块转换为swift时,xcode显示错误“调用中参数2缺少参数”,这是我编写的代码和屏幕截图:
目标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是一个属性。你在试着设置它。你的等号在哪里?这就是你如何设置的东西迅速:

 myThing.myProperty = myValue

试图将此属性设置为块(函数)的事实不会改变任何内容。所以:
let actionSheet = JGActionSheet(sections: sections)
actionSheet.buttonPressedBlock = {
    (sheet: JGActionSheet!, indexPath: NSIndexPath!) in
    actionSheet.dismissAnimated(true)
}

10-08 11:39