gpt4 book ai didi

ios - 我没有在 pod 'DropDown' 中得到我选择的值

转载 作者:行者123 更新时间:2023-11-28 23:29:18 26 4
gpt4 key购买 nike

我已经在我的项目中安装了 pod 'DropDown'。当我按下按钮时,它会显示带有月份列表的下拉菜单,当我从列表中选择月份时,它应该显示在按钮的位置,就像每个下拉菜单一样有效,但我无法获得我选择的值。按钮空间保持空白。

var dropDown = DropDown()

@IBAction func dropDownButtonTapped(_ sender: UIButton) {

dropDown.anchorView = dropDownButton

dropDown.dataSource = ["1","2","3","4","1","2","3","4"]
dropDown.show()

dropDown.selectionAction = { [unowned self] (index: Int, item: String) in
print("Selected item: \(item) at index: \(index)")
}

dropDown.direction = .bottom

}

最佳答案

您需要创建 UIButtonoutlet 或从方法参数 sender 获取按钮。

下面我创建了 socket ,并在 dropDown.selectionAction 中设置了选择时的按钮标题。

class ViewController: UIViewController {

let dropDown = DropDown()
@IBOutlet weak var menuButton: UIButton!

override func viewDidLoad() {
super.viewDidLoad()
dropDown.anchorView = menuButton
dropDown.dataSource = ["1","2","3","4","1","2","3","4"]

}

@IBAction func dropDownButtonTapped(_ sender: UIButton) {
dropDown.show()
dropDown.selectionAction = { [unowned self] (index: Int, item: String) in
print("Selected item: \(item) at index: \(index)")
self.menuButton.setTitle(item,for: .normal)
}
}
}

干杯!

关于ios - 我没有在 pod 'DropDown' 中得到我选择的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57353391/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com