简体   繁体   English

检查下拉列表的文本是否有效打开下一个选择器 usnig Swift

[英]check the text of the drop down list is valid to open the next picker usnig Swift

What I'm Using:我在用什么:

I'm using iOSDropDown Pod for showing list as a picker for any textField我正在使用 iOSDropDown Pod 将列表显示为任何文本字段的选择器


What I want to achieve:我想要达到的目标:

I have two textfields one for ProfileType called profileTypeField and the other is category of that profileTypeField called cateoryField And there Class are of type IosDropDown: instead of UITextField!我有两个文本字段,一个用于 ProfileType,称为 profileTypeField,另一个是该 profileTypeField 的类别,称为 cateoryField 并且 Class 的类型为 IosDropDown:而不是 UITextField! using the way of this pod I mentioned so what I want is:使用我提到的这个 pod 的方式,所以我想要的是:

Explanation解释

if I selected a certain text like "Store" from profileTypeField using dropdown list of this pod I want the user to select only the the category of that ProfileType On categoryField and show this Category text In Picker Or dropdownlist with the data of this Category in the categoryField如果我使用此 pod 的下拉列表从 profileTypeField 中选择了某个文本,例如“Store”,我希望用户仅在 categoryField 上使用该 ProfileType 的类别 select 并在 Picker 或下拉列表中显示此类别文本,其中包含此类别的数据类别字段


my code that I've tried:我尝试过的代码:

override func viewDidAppear(_ animated: Bool) {
        super.viewDidAppear(animated)
    
    let option =  Options()
    profileTypeField.optionArray = option.profileTypes
    profileTypeField.optionIds = option.ids
    profileTypeField.checkMarkEnabled = true
    profileTypeField.isSearchEnable = false
    
    
    if (profileTypeField.selectedIndex == Int("Store")) {
        categoryField.optionArray = option.storeIndividualCategory
        categoryField.optionIds = option.ids
        categoryField.checkMarkEnabled = true
        categoryField.isSearchEnable = true
    }
    else if (profileTypeField.selectedIndex == Int("Service")) {
        categoryField.optionArray = option.serviceCategory
        categoryField.optionIds = option.ids
        categoryField.checkMarkEnabled = true
        categoryField.isSearchEnable = true
    }
    else {
        categoryField.optionArray = option.MediaCategory
        categoryField.optionIds = option.ids
        categoryField.checkMarkEnabled = true
        categoryField.isSearchEnable = false
    }
}

but it achieves only the first case of if statement and it doesn't perform the last of the code但它只实现了 if 语句的第一种情况,它不执行最后的代码

profileTypeField.didSelect { (text, index, id) in profileTypeField.didSelect { (text, index, id) in

} }

Inside this you can get the categories related to profile type assign them to categoryTextField.optionArray then enable categoryTextField在此您可以获取与配置文件类型相关的类别,将它们分配给 categoryTextField.optionArray 然后启用 categoryTextField

Hope it helps.希望能帮助到你。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM