title: Multiple Section in UICollectionView
body: <p>I was building an iOS app for my hospital using collection view. However, I need to use multiple sections for the specialist clinic depends on the purpose. I already completed the code if it's just for 1 section. when I try to make it 2 sections, it always returns a nil value.</p>
  
  <p>please check my code below </p>
  
  <pre><code>public func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -&gt; UICollectionViewCell {
      let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cell", for: indexPath)
  
      if indexPath.section == 0 {
          var buttonSpecialist = cell.viewWithTag(1) as! UIButton
  
          buttonSpecialist.setTitle(list[indexPath.row].SpecialtyName, for: .normal)
  
          let btnimg = try? UIImage(data: Data(contentsOf: URL(string: list[indexPath.row].ImageUrl)!))
  
          var newimg = imageResize(image: btnimg as! UIImage, scaledTo: CGSize(width: 50, height: 50))
  
          buttonSpecialist.setImage(newimg, for: .normal)
          buttonSpecialist.contentMode = .center
          buttonSpecialist.imageView?.contentMode = .scaleAspectFit
  
          //let sign: Int = imageOnTop ? 1 : -1
          let imageSize: CGSize? = buttonSpecialist.imageView?.frame.size
          buttonSpecialist.titleEdgeInsets = UIEdgeInsetsMake(((imageSize?.height)! + 5) * 1, -(imageSize?.width)!, 0, 0)
          let titleSize: CGSize? = buttonSpecialist.titleLabel?.bounds.size
          buttonSpecialist.imageEdgeInsets = UIEdgeInsetsMake(-((titleSize?.height)! + 5) * 1, 0, 0, -(titleSize?.width)!)
  
          cell.layer.borderWidth = 1.0
          cell.layer.borderColor = UIColor.black.cgColor
      }
      else if indexPath.section == 1 {
          var buttonSpecialist = cell.viewWithTag(1) as! UIButton
  
          buttonSpecialist.setTitle(list2[indexPath.row].SpecialtyName, for: .normal)
  
          let btnimg = try? UIImage(data: Data(contentsOf: URL(string: list2[indexPath.row].ImageUrl)!))
  
          var newimg = imageResize(image: btnimg as! UIImage, scaledTo: CGSize(width: 50, height: 50))
  
          buttonSpecialist.setImage(newimg, for: .normal)
          buttonSpecialist.contentMode = .center
          buttonSpecialist.imageView?.contentMode = .scaleAspectFit
  
          //let sign: Int = imageOnTop ? 1 : -1
          let imageSize: CGSize? = buttonSpecialist.imageView?.frame.size
          buttonSpecialist.titleEdgeInsets = UIEdgeInsetsMake(((imageSize?.height)! + 5) * 1, -(imageSize?.width)!, 0, 0)
          let titleSize: CGSize? = buttonSpecialist.titleLabel?.bounds.size
          buttonSpecialist.imageEdgeInsets = UIEdgeInsetsMake(-((titleSize?.height)! + 5) * 1, 0, 0, -(titleSize?.width)!)
  
          cell.layer.borderWidth = 1.0
          cell.layer.borderColor = UIColor.black.cgColor
      }
  </code></pre>
  
  <p>The main problem here is, I didn't know how to set the specific cell for the specific section. I already using 'IF' inside the function 'cellforindexpath', but it didn't worked.</p>
  
  <p>this is my return number of items in section </p>
  
  <pre><code>func numberOfSections(in collectionView: UICollectionView) -&gt; Int {
      // #warning Incomplete implementation, return the number of sections
      return 2
  }
  
  
  func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -&gt; Int {
      // #warning Incomplete implementation, return the number of items
  
      if section == 0 {
          return list.count
      }
          else if section == 1{
              return list2.count
          }
  
      return 0
  
  }
  </code></pre>
  
  <p>please help me</p>