只是一个粗略的草图:
说你从你PickerView选择一个类别。然后,您的PickerView应该通知您父ViewController用户选择了一个类别。最方便的方式做到这一点是有一个Delegate方法,如:
self.delegate.userPickedCategory(pickedCategory: Category)
现在,我想你Category
对象包含子类别的数组:
class Category: NSObject {
var title: NSString!
var subCategories: NSMutableArray!
//some variable containing categories content
}
说你命名的按钮,使子类别菜单subCategoryButton
。您应该始终设置hidden = true
或至少userInteractionEnabled = false
,因为您不知道所选类别是否有子。
如果你的父母的ViewController收到您的用户选择了一个类别的委托方法,你可以这样做:
func userPickedCategory(pickedCategory: Category) {
if pickedCategory.subcategories != nil || pickedCategory.subCategories.count != 0 {
//you now know the picked category has a subCategory
//so allow the user to pick that subCategory by enabling this button
self.subCategoryButton.hidden = false
self.subCategoryButton.userInteractionEnabled = true
}
然后,你需要确保subCategoryButton
显示包含您挑选类别的子类别另一个选择器视图
非常感谢,设法解决您的答案 –