我正在使用这个 ZHDropDownMenuDelegate我的下拉列表选项的库。现在我有两个下拉选项。例如,我下拉了国家,州。下面是示例代码:
Emenu1.options = ["1","2","3"]
Emenu2.options = ["1a","2b","3c"]
现在使用这两种方法函数我可以获得我选择的下拉选项:
func dropDownMenu(menu: ZHDropDownMenu!, didChoose index: Int) {
print("\(menu) choosed at index \(index)")
let country : NSString = Emenu1.options .objectAtIndex(index) as! NSString
ECountryInputName.text = country as String
let secondmenu : NSString = Emenu2.options .objectAtIndex(index) as! NSString
IamInputName.text! = secondmenu as String!
print(IamInputName.text)
}
//编辑完成后回调
func dropDownMenu(menu: ZHDropDownMenu!, didInput text: String!) {
// print("\(menu) input text \(text)")
}
所以在第一个菜单中,如果我选择 1
,那么在我的第二个菜单中,它会自动选择 1a
。
如果我在第二个菜单中选择 2a
,那么在第一个菜单中 2
会自动选择。
现在我如何在不使用索引值的情况下单独选择我的选项。请帮助我!!
谢谢
最佳答案
在您的 Storyboard
中为每个菜单(ZHDropDownMenu)
设置标签
,然后执行以下操作:
func dropDownMenu(menu: ZHDropDownMenu!, didChoose index: Int) {
if menu.tag == 0 {
let country : NSString = Emenu1.options .objectAtIndex(index) as! NSString
ECountryInputName.text = country as String
}else if menu.tag == 1 {
let secondmenu : NSString = Emenu2.options .objectAtIndex(index) as! NSString
IamInputName.text! = secondmenu as String!
}
}
关于ios - 如何将下拉文本值获取到 label.text,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41004672/