Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
atalw opened this issue Nov 20, 2017 · 4 comments

Comments

@atalw
Copy link

atalw commented Nov 20, 2017

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

@rursache
Copy link

you could subclass then publish events to your main vc

@HSISean
Copy link

HSISean commented Dec 8, 2018

How would you then access it?

@Turgunov
Copy link

Turgunov commented Dec 20, 2018

@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

@HSISean
Copy link

HSISean commented Dec 21, 2018

Thank you so much @Turgunov !!!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants