YNDropDownMenu icon indicating copy to clipboard operation
YNDropDownMenu copied to clipboard

How do I use the values set in the drop down views to sort the tableView of the main controller?

Open atalw opened this issue 8 years ago • 4 comments

There is no example code that does this and neither is there documentation. Is it supported or is this framework purely front-end?

atalw avatar Nov 20 '17 13:11 atalw

you could subclass then publish events to your main vc

rursache avatar Dec 20 '17 17:12 rursache

How would you then access it?

HSISean avatar Dec 08 '18 16:12 HSISean

@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

Turgunov avatar Dec 20 '18 03:12 Turgunov

Thank you so much @Turgunov !!!!

HSISean avatar Dec 21 '18 13:12 HSISean