gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-28 14:02:30 34 4
gpt4 key购买 nike

我在我的项目中使用这个下拉框: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)。您可以为按钮分配一个标签,并在调用委托(delegate)方法时检查此属性。

例如:typeDropper.tag = 1

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

关于ios - 我怎么知道将下拉框的选定内容放在哪个按钮中。Swift,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53410922/

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