title: iOS spreadsheetview not able to display multiple blocks in cell
body: <p>I’m using Spreadsheetview library in order to show case Jobber functionality.
  There is one critical issues which is blocking project release. This is mentioned below:</p>
  <p><strong>Problem:</strong> Not able to display multi block content in custom cell.</p>
  <p><strong>Scenario:</strong> Suppose userA has task1 from 10:00 AM to 12:00 AM, userB has task2 from 10:00 AM to 11:00 AM, userC has task3 from 10:00 AM to 11:30 AM so these three task should be displayed in merged cell with one after another.</p>
  <p>Refer below screenshot.</p>
  <p><a href="https://i.stack.imgur.com/8Hbc5.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/8Hbc5.jpg" alt="Screenshot" /></a></p>
  <p><strong>Code:</strong></p>
  <pre><code>func spreadsheetView(_ spreadsheetView: SpreadsheetView, cellForItemAt indexPath: IndexPath) -&gt; Cell? {
  
          if self.jobDetails == nil {
              return nil
          }
  . . . 
  
  //other cases handled like displaying time, date, visit person name which is not having any issue
  . . .
  
  else if case (1...(calenderData.count + 1), 2...(Constants.timeIntervals.count + 1)) = (indexPath.column, indexPath.row) {
  
   let cell = spreadsheetView.dequeueReusableCell(withReuseIdentifier: String(describing: ScheduleCell1.self), for: indexPath) as! ScheduleCell1
              if(cell.firstBlockLabel.text != nil) || (cell.secondBlockLabel.text != nil) || (cell.thirdBlockLabel.text != nil) {
                  return nil
              }
  
  let visits = calenderData[indexPath.column - 1].calendarRows
              for visit in visits {
                  let diff = findTimeDifference(firstTime: cellTime,secondTime: visit.startTime)
                  print(&quot;startTime: \(visit.startTime) endTime \(visit.endTime) title \(visit.title) totalBlocks \(visit.totalBlocks)&quot;)
                  
                  if(diff &gt;= -30 &amp;&amp; diff &lt;= 30 &amp;&amp; diff != -1) {
                      switch visit.totalBlocks {
                      case 0,1:
                          cell.firstBlockLabel.isHidden = false
                          cell.secondBlockLabel.isHidden = true
                          cell.thirdBlockLabel.isHidden = true
                          
                          cell.firstBlockLabel.text = &quot;1 - case 1&quot;
                          if visit.blockSerialNo == 1 {
                              if(visit.statusCode.caseInsensitiveCompare(&quot;completed&quot;) == .orderedSame){
                                  cell.firstBlockLabel.attributedText = &quot;\(visit.title)&quot;.strikeThrough()
                              } else {
                                  cell.firstBlockLabel.text = &quot;\(visit.title)&quot;
                              }
                              
                              cell.firstBlockLabel.backgroundColor = hexStringToUIColor(hex: visit.statusTagProp.background)
                              cell.firstBlockLabel.textColor = hexStringToUIColor(hex: visit.statusTagProp.text)
                          }
                      case 2:
                          cell.firstBlockLabel.isHidden = false
                          cell.secondBlockLabel.isHidden = false
                          cell.thirdBlockLabel.isHidden = true
                          
                          cell.firstBlockLabel.text = &quot;1 - case 2&quot;
                          cell.secondBlockLabel.text = &quot;2 - case 2&quot;
                          
                          if visit.blockSerialNo == 2 {
                              if(visit.statusCode.caseInsensitiveCompare(&quot;completed&quot;) == .orderedSame){
                                  cell.secondBlockLabel.attributedText = &quot;\(visit.title)&quot;.strikeThrough()
                              } else {
                                  cell.secondBlockLabel.text = &quot;\(visit.title)&quot;
                              }
                              
                              cell.secondBlockLabel.backgroundColor = hexStringToUIColor(hex: visit.statusTagProp.background)
                              cell.secondBlockLabel.textColor = hexStringToUIColor(hex: visit.statusTagProp.text)
                          }
                      case 3:
                          cell.firstBlockLabel.isHidden = false
                          cell.secondBlockLabel.isHidden = false
                          cell.thirdBlockLabel.isHidden = false
                          
                          cell.firstBlockLabel.text = &quot;1 - case 3&quot;
                          cell.secondBlockLabel.text = &quot;2 - case 3&quot;
                          cell.thirdBlockLabel.text = &quot;3 - case 3&quot;
                          
                          if visit.blockSerialNo == 3 {
                              if(visit.statusCode.caseInsensitiveCompare(&quot;completed&quot;) == .orderedSame){
                                  cell.thirdBlockLabel.attributedText = &quot;\(visit.title)&quot;.strikeThrough()
                              } else {
                                  cell.thirdBlockLabel.text = &quot;\(visit.title)&quot;
                              }
                              
                              cell.thirdBlockLabel.backgroundColor = hexStringToUIColor(hex: visit.statusTagProp.background)
                              cell.thirdBlockLabel.textColor = hexStringToUIColor(hex: visit.statusTagProp.text)
                          }
                      default:
                          break
                      }
  
  break
                  }
              }
              return cell
  }
          return nil
      }
  
  
  
  class ScheduleCell1: Cell {
      let firstBlockLabel = UILabel()
      let secondBlockLabel = UILabel()
      let thirdBlockLabel = UILabel()
      let stackview = UIStackView()
      
      let lineLabel = UILabel()
      var lineYPosition: Int = 0
      
     override var frame: CGRect {
          didSet {
              firstBlockLabel.frame = CGRect(x: 0, y: 0, width: 500, height: 500)
              secondBlockLabel.frame = CGRect(x: 0, y: 0, width: 500, height: 500)
              thirdBlockLabel.frame = CGRect(x: 0, y: 0, width: 500, height: 500)
              
              lineLabel.frame = bounds.insetBy(dx: 0, dy: 0)
              lineLabel.frame = CGRect(x: 0, y: lineYPosition, width: 300, height: 1)
          }
      }
      
      override init(frame: CGRect) {
          super.init(frame: frame)
          
          lineLabel.frame = bounds
          lineLabel.backgroundColor = .red
          
          firstBlockLabel.textAlignment = .center
          //firstBlockLabel.text = &quot;firstBlockLabel&quot;
          firstBlockLabel.numberOfLines = 0
          firstBlockLabel.lineBreakMode = .byTruncatingTail
          firstBlockLabel.translatesAutoresizingMaskIntoConstraints = false
          
          secondBlockLabel.textAlignment = .center
          //secondBlockLabel.text = &quot;secondBlockLabel&quot;
          secondBlockLabel.numberOfLines = 0
          secondBlockLabel.lineBreakMode = .byTruncatingTail
          secondBlockLabel.translatesAutoresizingMaskIntoConstraints = false
          
          thirdBlockLabel.textAlignment = .center
          //thirdBlockLabel.text = &quot;thirdBlockLabel&quot;
          thirdBlockLabel.numberOfLines = 0
          thirdBlockLabel.lineBreakMode = .byTruncatingTail
          thirdBlockLabel.translatesAutoresizingMaskIntoConstraints = false
          
          stackview.frame = bounds
          stackview.axis = .horizontal
          stackview.spacing = .leastNonzeroMagnitude
          stackview.contentMode = .scaleToFill
          stackview.translatesAutoresizingMaskIntoConstraints = false
          stackview.alignment = .fill
          stackview.distribution = .fill
          stackview.distribution = .fillProportionally
          
          stackview.addArrangedSubview(firstBlockLabel)
          stackview.addArrangedSubview(secondBlockLabel)
          stackview.addArrangedSubview(thirdBlockLabel)
          
          firstBlockLabel.backgroundColor = .yellow
          secondBlockLabel.backgroundColor = .purple
          thirdBlockLabel.backgroundColor = .green
          stackview.backgroundColor = .magenta
          //contentView.backgroundColor = .magenta
          
          contentView.addSubview(lineLabel)
          contentView.bringSubviewToFront(lineLabel)
          contentView.addSubview(stackview)
          
          stackview.leadingAnchor.constraint(equalTo: contentView.leadingAnchor).isActive = true
          stackview.trailingAnchor.constraint(equalTo: contentView.trailingAnchor).isActive = true
      }
      
      required init?(coder aDecoder: NSCoder) {
          super.init(coder: aDecoder)
      }
  }
  </code></pre>
  <p>So I’ve added two property totalBlocks (determines how may blocks to be displayed) and BlockSrNo (determines which serial number of block). Logic for this is mentioned below:</p>
  <pre><code>func determineMultiBlocks() {
          for data in calenderData {
              let visits = data.calendarRows
  
  for var i in 0..&lt;visits.count {
                  let visit = visits[i]
                  
                  for var j in (i+1)..&lt;visits.count {
                      let nextVisit = visits[j]
  
  let timeOverlapExists = CheckIfTimeExistBetweenTwoTimeInterval(withStartTime: visit.startTime.timeInSeconds, withEndTime: visit.endTime.timeInSeconds, withTimeToCheck: nextVisit.startTime.timeInSeconds)
  
  if timeOverlapExists {
  
  visit.totalBlocks = visit.totalBlocks + 1
                          nextVisit.totalBlocks = 0 //nextVisit.totalBlocks - 1
                          nextVisit.blockSerialNo = visit.totalBlocks
                          
                          j = j + 1
  }
                  }
  break
              }
  </code></pre>
  <p>Can help me where am I going wrong? If there is any other solution instead of using totalBlocks/blockSerialNo then let me know.</p>
  <p>Appreciate all solutions!</p>