多个 Parameters/Arguments 用于操作 - Swift

Multiple Parameters/Arguments for Action - Swift

我发现了一个与我最相似的问题,但是没有得到彻底的回答。如果有人能帮助我,那就太好了。我发现类似问题的地方是here.

我很清楚 func test()"test"test(object:AnyObject)"test:"。感谢 this.

那么2个参数呢? swift 不能为 'action:' 做 2 个参数吗?

func popoverSelectedCode (code:AnyObject, desc:AnyObject)

我尝试通过以下几种不同的方式对其进行测试,但无济于事:

action: "popoverSelectedCode:,"

action: "popoverSelectedCode:,:"

action: "popoverSelectedCode: :"

action: "popoverSelectedCode: , :"

我才一周大 Swift 所以请善待。

已编辑 这是代码的一小段

@IBAction func securityQuestButtonClicked (sender:AnyObject)
{
    cellButton = sender as? UIButton;

    var comboDescListArray = TableRoutine.loadCombobox("MobileQuestion")

    var codeObject : NSArray = comboDescListArray[0] as NSArray;
    var descObject : NSArray = comboDescListArray[1] as NSArray;

    var selectionTVC = CPSelectionTVC(style:UITableViewStyle.Plain, codeArray:codeObject, descArray:descObject, target:self, action: "popoverSelectedCode::", widthForViewInPopover:650)

    let navCtl = UINavigationController.init(rootViewController:selectionTVC)
    popoverController = UIPopoverController.init(contentViewController:navCtl)

    var contentHeight : CGFloat = CGFloat (UInt(selectionTVC.navigationTitleHeight) + UInt(selectionTVC.rowCount()) * UInt(selectionTVC.cellHeight))

    popoverController?.popoverContentSize = CGSizeMake(400.0, contentHeight)
    popoverController?.presentPopoverFromRect(sender.bounds, inView:sender as UIView, permittedArrowDirections:UIPopoverArrowDirection.Up, animated:true)
}

弹出窗口出现,但是在选择时,它只是挂起。

有了两个参数就变成了action::。一个参数一个冒号。

如果函数有如下两个参数。

func clicked(sender:AnyObject,value:AnyObject)
{
}

然后

action = "clicked::"

根据您的情况,您可以通过以下方式实现它:

action: "popoverSelectedCode:desc:"

检查下面的代码

func switchCard(card: Int, withCard card1: Int) {
    print(card)
}
let singleTap1 = UITapGestureRecognizer(target: self, action: "switchCard:withCard:")

请注意 Swift 2.2。 您现在可以将选择器键入

#selector(popoverSelectedCode(_:desc:)

对于在选择器方法中传递的多个参数:

let swipeRecognizer = UISwipeGestureRecognizer.init(target: self, action: #selector(ImageViewController.handleTap(_: sender :)))
myCell.imageViewPhoto .addGestureRecognizer(swipeRecognizer)

Swift 2.2 中你可以这样做。

myUISlider.addTarget(self, action:#selector(self.onSliderValChanged(_:withEvent:)), forControlEvents: .ValueChanged)

func onSliderValChanged(slider: UISlider, withEvent event: UIEvent?) {
    }

我希望它能帮助到那里的人。