title: iOS Swift CollectionView delegate not getting called
body: <p>I have conformed the protocols <code>UICollectionViewDelegate, UICollectionViewDelegateFlowLayout, UIScrollViewDelegate</code> to a seperate class named <code>CollectionViewWeekDelegate</code> but the delegate methods such as <code>didSelectItemAt</code> is not getting called.</p>
  
  <p>I'm also setting the delegate to <code>CollectionView</code> in <code>viewDidLoad()</code></p>
  
  <p>Please find the code below:</p>
  
  <p>Delegate Class</p>
  
  <pre><code>class CollectionViewWeekDelegate: NSObject, UICollectionViewDelegate, UICollectionViewDelegateFlowLayout, UIScrollViewDelegate {
  
      internal var parent: EarningsViewController?
  
      func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
  
          parent?.weekTabSelectedPosition = indexPath.item
  
          let indexPathh = IndexPath(item: indexPath.item, section: 0)
  
          parent?.collectionViewSchedule.scrollToItem(at: indexPathh, at: .right, animated: true)
          parent?.collectionViewWeeks.scrollToItem(at: indexPath, at: .top, animated: true)
  
          parent?.collectionViewWeeks.reloadData()
  
      }
  
  
      func scrollViewDidEndDecelerating(_ scrollView: UIScrollView) {
  
          let offsetX = parent?.collectionViewSchedule.contentOffset.x
          let contentWidth = parent?.collectionViewSchedule.bounds.width
  
          let page = Int(offsetX! / contentWidth!)
  
          parent?.weekTabSelectedPosition = page
  
  
  
          var earningsText  = "\("grossEarnings".localize()) $\(String(format: "%0.2f", 0.0))"
  
          if let earnings = parent?.schedules?[page].grossWeekSalary{
              earningsText = "\("grossEarnings".localize()) $\(String(format: "%0.2f", earnings))"
  
  
              parent?.buttonGrossEarnings.setTitle(earningsText, for: .normal)
  
              parent?.collectionViewWeeks.selectItem(at: IndexPath(item: page, section: 0), animated: true, scrollPosition: .centeredHorizontally)}
      }
  
      func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -&gt; CGSize {
          if collectionView.tag == 2{
              return CGSize(width: UIScreen.main.bounds.width, height: (parent?.collectionViewSchedule.bounds.height)!)
          }else{
              return CGSize(width: 150, height: 50)
          }
      }
  }
  </code></pre>
  
  <p>viewDidLoad function where the <code>CollectionView</code> delegate is being assigned:</p>
  
  <pre><code>override func viewDidLoad() {
      super.viewDidLoad()
      self.navigationController?.title = "schedule".localize()
  
      self.navigationItem.leftBarButtonItem = super.getMenuBartItem()
  
      if let flowLayout = collectionViewWeeks.collectionViewLayout as? UICollectionViewFlowLayout{
          flowLayout.estimatedItemSize = CGSize(width: 150, height: 50)
      }
  
      if let collectionFlowLayout = collectionViewSchedule.collectionViewLayout as? UICollectionViewFlowLayout{
          collectionFlowLayout.minimumLineSpacing = 0
          collectionFlowLayout.minimumInteritemSpacing = 0
  
      }
  
      let weekDelegate = CollectionViewWeekDelegate()
      weekDelegate.parent = self
  
      collectionViewWeeks.delegate = weekDelegate
      collectionViewSchedule.delegate = self
  
      collectionViewWeeks.reloadData()
  }
  </code></pre>