YNDropDownMenu
YNDropDownMenu copied to clipboard
How do I use the values set in the drop down views to sort the tableView of the main controller?
There is no example code that does this and neither is there documentation. Is it supported or is this framework purely front-end?
you could subclass then publish events to your main vc
How would you then access it?
@atalw I found a basic solution to this issue using delegates.
protocol FilterViewDelegate {
func didChangeSubcategory(segmentedControl: UISegmentedControl)
func didChangeAvailability(segmentedControl: UISegmentedControl)
func didChangeQuality(segmentedControl: UISegmentedControl)
}
class CategoryView: YNDropDownView {
@IBOutlet var subcategorySegmentControl: UISegmentedControl!
var filterViewDelegate: FilterViewDelegate?
override init(frame: CGRect) {
super.init(frame: frame)
self.backgroundColor = UIColor.white
self.initViews()
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
self.initViews()
}
@IBAction func confirmButtonClicked(_ sender: Any) {
filterViewDelegate?.didChangeSubcategory(segmentedControl: subcategorySegmentControl)
self.hideMenu()
}
@IBAction func cancelButtonClicked(_ sender: Any) {
self.hideMenu()
}
override func dropDownViewOpened() {
//print("dropDownViewOpened")
}
override func dropDownViewClosed() {
//print("dropDownViewClosed")
}
func initViews() {
}
}
class ProductView: YNDropDownView {
@IBOutlet var availabilitySegmentControl: UISegmentedControl!
@IBOutlet var quailitySegmentControl: UISegmentedControl!
var filterViewDelegate: FilterViewDelegate?
override init(frame: CGRect) {
super.init(frame: frame)
self.backgroundColor = UIColor.white
self.initViews()
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
self.initViews()
}
@IBAction func confirmButtonClicked(_ sender: Any) {
filterViewDelegate?.didChangeAvailability(segmentedControl: availabilitySegmentControl)
filterViewDelegate?.didChangeQuality(segmentedControl: quailitySegmentControl)
self.hideMenu()
}
@IBAction func cancelButtonClicked(_ sender: Any) {
self.hideMenu()
}
func initViews() {
}
}
** ProductListViewController - MainVC**
func setupZBDropDownViews() {
let ZBdropDownViews = Bundle.main.loadNibNamed("DropDownViews", owner: nil, options: nil) as? [UIView]
ZBdropDownViews?.forEach({ (dropDownView) in
if dropDownView.isKind(of: CategoryView.self) {
(dropDownView as? CategoryView)?.filterViewDelegate = self
}
if dropDownView.isKind(of: ProductView.self) {
(dropDownView as? ProductView)?.filterViewDelegate = self
}
})
}
extension ProductListViewController: FilterViewDelegate {
func didChangeSubcategory(segmentedControl: UISegmentedControl) {
print("didChangeSubcategory")
}
func didChangeAvailability(segmentedControl: UISegmentedControl) {
print("didChangeAvailability")
}
func didChangeQuality(segmentedControl: UISegmentedControl) {
print("didChangeQuality")
}
}
I hope it will help someone with the same problem
Thank you so much @Turgunov !!!!