Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple Parameters/Arguments for Action - Swift

I found a question most similar to mine however it was not thoroughly answered. It would be great if anyone could help me out. The place where I found the similar question is here.

I understand clearly how func test() would be "test" and test(object:AnyObject) would be "test:". Thanks to this.

So how about 2 parameters? Can swift not do 2 arguments for 'action:'?

func popoverSelectedCode (code:AnyObject, desc:AnyObject)

I tried testing it out in few different ways below, but to no avail:

action: "popoverSelectedCode:,"

action: "popoverSelectedCode:,:"

action: "popoverSelectedCode: :"

action: "popoverSelectedCode: , :"

Am only about a week's old in Swift so please be kind.

EDITED Here is a short clip of the code

@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)
}

The popover appears however upon selecting, it just hangs.

like image 585
Rach Ng Avatar asked Jan 13 '15 07:01

Rach Ng


2 Answers

Just a note on Swift 2.2. You can now type the selector as

#selector(popoverSelectedCode(_:desc:)
like image 70
Erik Johansson Avatar answered Sep 28 '22 09:09

Erik Johansson


check this below code

func switchCard(card: Int, withCard card1: Int) {
    print(card)
}
let singleTap1 = UITapGestureRecognizer(target: self, action: "switchCard:withCard:")
like image 24
Narendra G Avatar answered Sep 28 '22 08:09

Narendra G