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

When I open the side menu everything in the front view controller class become nil #810

Open
abdulelah1 opened this issue Mar 28, 2019 · 0 comments

Comments

@abdulelah1
Copy link

Hi
When I open the side menu everything in the front view controller class become nil

Here is my code

ResultsViewController.swift
`
class ResultsViewController: UIViewController, UICollectionViewDelegate, UICollectionViewDataSource, sideMenuDelegate {

override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(true)

    self.Search()
    print("Collection: \(self.collectionView)") // not nil
    self.collectionView.frame = self.contentView.frame
    
    self.collectionView.register(UINib.init(nibName: "ResultsGridCell", bundle: nil), forCellWithReuseIdentifier: "ResultsGridCell")
    
    let layout: UICollectionViewFlowLayout = UICollectionViewFlowLayout()
    layout.sectionInset = UIEdgeInsets(top: 20, left: 10, bottom: 10, right: 10)
    layout.itemSize = CGSize(width: (self.contentView.frame.size.width - 16), height: 98)
    
    self.listCollectionView = UICollectionView(frame: self.contentView.frame, collectionViewLayout: layout)
    self.listCollectionView?.dataSource = self
    self.listCollectionView?.delegate = self
    self.listCollectionView?.register(UINib.init(nibName: "ResultsCell", bundle: nil) , forCellWithReuseIdentifier: "ResultsListCell")
    self.listCollectionView?.backgroundColor = UIColor.white
    self.listCollectionView?.isHidden = true
    self.view.addSubview(self.listCollectionView!)
}

override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(true)
if self.revealViewController() != nil {

        self.filterSideMenuButton.target = self.revealViewController()
        self.filterSideMenuButton.action = "revealToggle:"
        
        self.view.addGestureRecognizer((self.revealViewController()?.panGestureRecognizer())!)
        self.view.addGestureRecognizer((self.revealViewController()?.tapGestureRecognizer())!)
    }
}

func applyFilters(sender: UIButton, rating: NSNumber?, max: NSNumber?, min: NSNumber?) {

    print(self.revealViewController()) // nil
    self.revealViewController()?.revealToggle(true)
    print(self.collectionView) // nil
}

}
`

SideMenuViewController

`@objc
public protocol sideMenuDelegate {
func applyFilters(sender: UIButton, rating: NSNumber?, max: NSNumber?, min: NSNumber?)
func cancelFilters()
}

class SideMenuViewController: UIViewController {

var rating = 0

var myDelegate: sideMenuDelegate?

@IBOutlet weak var rating1: CosmosView!

@IBOutlet weak var rating2: CosmosView!

@IBOutlet weak var rating3: CosmosView!

@IBOutlet weak var rating4: CosmosView!

@IBOutlet weak var rating5: CosmosView!

@IBOutlet weak var maximumTextField: UITextField!

@IBOutlet weak var minimumTextField: UITextField!

@IBOutlet weak var filterCancelationButton: UIButton!

@IBOutlet weak var applyFiltersButton: UIButton!

override func viewDidLoad() {
    super.viewDidLoad()
    
    let ratingTapRecognizer1 = UITapGestureRecognizer()
    ratingTapRecognizer1.addTarget(self, action: #selector(self.ratingTapped(sender:)))
    
    let ratingTapRecognizer2 = UITapGestureRecognizer()
    ratingTapRecognizer2.addTarget(self, action: #selector(self.ratingTapped(sender:)))
    
    let ratingTapRecognizer3 = UITapGestureRecognizer()
    ratingTapRecognizer3.addTarget(self, action: #selector(self.ratingTapped(sender:)))
    
    let ratingTapRecognizer4 = UITapGestureRecognizer()
    ratingTapRecognizer4.addTarget(self, action: #selector(self.ratingTapped(sender:)))
    
    let ratingTapRecognizer5 = UITapGestureRecognizer()
    ratingTapRecognizer5.addTarget(self, action: #selector(self.ratingTapped(sender:)))
    
    self.rating1.addGestureRecognizer(ratingTapRecognizer1)
    self.rating2.addGestureRecognizer(ratingTapRecognizer2)
    self.rating3.addGestureRecognizer(ratingTapRecognizer3)
    self.rating4.addGestureRecognizer(ratingTapRecognizer4)
    self.rating5.addGestureRecognizer(ratingTapRecognizer5)
    
    for i in 1...5 {
       let ratingBar = self.view.viewWithTag(i) as! CosmosView
        ratingBar.settings.filledColor = UIColor.init(red: 40/255, green: 40/255, blue: 40/255, alpha: 1)
        ratingBar.settings.filledBorderColor = UIColor.init(red: 40/255, green: 40/255, blue: 40/255, alpha: 1)
    }
    
    self.filterCancelationButton.layer.borderWidth = 1
    self.filterCancelationButton.layer.borderColor = UIColor.init(red: 230/255, green: 99/255, blue: 69/255, alpha: 1).cgColor
    
    self.applyFiltersButton.addTarget(self, action: #selector(self.applyTapped), for: .touchUpInside)
    
    self.filterCancelationButton.addTarget(self, action: #selector(self.cancelFilters), for: .touchUpInside)
    
}

@objc
func applyTapped(sender: UIButton) {
    
    var max: Int? = nil
    var min: Int? = nil
    
    if self.maximumTextField.text != "" {
        max = Int(self.maximumTextField.text!)
    }
    
    if self.minimumTextField.text != "" {
        min = Int(self.minimumTextField.text!)
    }
    
    myDelegate = ResultsViewController.self()
    myDelegate?.applyFilters(sender: sender, rating: rating as NSNumber, max: max as NSNumber?, min: min as NSNumber?)
    
    
}

}`

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

1 participant