我怎么知道将下拉框的选定内容放在哪个按钮中。Swift

how would I know what button to place the selected content of the dropdown box in. Swift

我在我的项目中使用这个下拉框:https://github.com/kirkbyo/Dropper

我想将下拉框中的选中项输入到按钮的文本中。但是,我有 3 个按钮,它们都带有下拉框,要找出已按下的项目,您可以使用 func DropperSelectedRow(_ path: IndexPath, contents: String) 方法,该方法将为您提供索引路径和所单击内容的字符串。在这种情况下,您只需将内容放入按钮文本中,但我不知道将其放入哪个按钮中。我如何找到它?

这是我的代码:

class ListComposerTableViewController: UITableViewController, UITextViewDelegate, DropperDelegate {

    @IBOutlet weak var typeButton: UIButton!
    @IBOutlet weak var dateButton: UIButton!
    @IBOutlet weak var publicButton: UIButton!

    let typeDropper = Dropper(width: 105, height: 105)
    let typeOptions = ["Event", "Birthday", "Christmas", "Charity"]

    let publicDropper = Dropper(width: 105, height: 105)
    let publicOptions = ["Public", "Private"]

    let dueDropper = Dropper(width: 105, height: 130)
    let dueOptions = ["Bithday", "Christmas", "Custom Date"]

    override func viewDidLoad() {
        super.viewDidLoad()

        //set up the droppers

        typeDropper.items = typeOptions // Item displayed
        typeDropper.maxHeight = 105
        typeDropper.theme = Dropper.Themes.black(UIColor.white)
        typeDropper.delegate = self
        typeDropper.cornerRadius = typeButton.layer.cornerRadius
        typeDropper.cellColor = Colours.flatColour.main.headings
        typeDropper.cellBackgroundColor = UIColor.white
        typeDropper.width = 105
        typeDropper.height = 105

        publicDropper.items = publicOptions // Item displayed
        publicDropper.maxHeight = 105
        publicDropper.theme = Dropper.Themes.black(UIColor.white)
        publicDropper.delegate = self
        publicDropper.cornerRadius = publicButton.layer.cornerRadius
        publicDropper.cellColor = Colours.flatColour.main.headings
        publicDropper.cellBackgroundColor = UIColor.white
        publicDropper.width = 105
        publicDropper.height = 105  

        dueDropper.items = dueOptions // Item displayed
        dueDropper.maxHeight = 130
        dueDropper.theme = Dropper.Themes.black(UIColor.white)
        dueDropper.delegate = self
        dueDropper.cornerRadius = publicButton.layer.cornerRadius
        dueDropper.cellColor = Colours.flatColour.main.headings
        dueDropper.cellBackgroundColor = UIColor.white
        dueDropper.width = 105
        dueDropper.height = 105
    }

    @IBAction func typeDidPress(_ sender: Any) {
        if typeDropper.status == .hidden {
            typeDropper.showWithAnimation(0.15, options: Dropper.Alignment.center, button: typeButton)
        } else {
            typeDropper.hideWithAnimation(0.1)
        }
    }
    @IBAction func dueDidPress(_ sender: Any) {
        if dueDropper.status == .hidden {
            dueDropper.showWithAnimation(0.15, options: Dropper.Alignment.center, button: dateButton)
        } else {
            dueDropper.hideWithAnimation(0.1)
        }
    }

    @IBAction func publicDidPress(_ sender: Any) {
        if publicDropper.status == .hidden {
            publicDropper.showWithAnimation(0.15, options: Dropper.Alignment.center, button: publicButton)
        } else {
        publicDropper.hideWithAnimation(0.1)
        }
    }

    func DropperSelectedRow(_ path: IndexPath, contents: String) {
        print(path)
        print(contents)
    }

如何将点击的内容放入滴管来源的按钮文本中?谢谢。

改用func DropperSelectedRow(_ path: IndexPath, contents: String, tag: Int)。 您可以为您的按钮分配一个标签,并在调用委托方法时检查此 属性。

例如:typeDropper.tag = 1

func DropperSelectedRow(_ path: IndexPath, contents: String, tag: Int) {
    if tag == 1 {
        typeButton.setTitle(contents, for: .normal)
    }
}