2016-12-06 32 views
0

我正在使用此ZHDropDownMenuDelegate库作为我的下拉列表选项。现在我有两个很多下拉选项。比如我有下拉的国家,state.Here下面的示例代码:如何获取下拉文本值到label.text

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中自动选择。

现在我怎么能单独选择我的选项,而不使用索引值。请帮助我!

感谢

+0

您需要检查您在'didChoose'方法中选择了哪个'menu'。您可能必须为每个“ZHDropDownMenu”设置“tag”,然后在“didChoose”方法中进行比较。 – Santosh

+0

我是新来的ios,知道设置标签值。例如,对于第一个菜单= 10,第二个菜单= 20。你可以给我一些代码片段,我怎么能比较。因为在这个库中,我很难找出它 – mack

回答

1

设置在storyboardtag每个menu (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! 
    } 
} 

请避免使用! S,它是一种邀请您的应用程序在某些时候崩溃的。 enter image description here

+0

那是可选的,我需要删除所有地方或任何特定部分? – mack

+0

非常感谢您的简单方法。 – mack