JTAppleCalendar icon indicating copy to clipboard operation
JTAppleCalendar copied to clipboard

Changing cell selection results in random cell deselection

Open Martinus1 opened this issue 5 years ago • 5 comments

(Required) Version Number: 8.0.3

Description

(multiple-selection) When cells are selected in my calendar sometimes the visual representation of the selection seems to not appear for some cells and it seems to be completely random. I don't exactly know why is this happening and have been struggling with this issue for quite a bit. Such as in the photo below, not all desired dates are selected. I have an array of dates that I want to select which I am comparing to "cellState.date". Simulator Screen Shot - iPhone 11 Pro - 2020-06-12 at 16 58 25

Expected Behavior

All desired cells are selected.

Martinus1 avatar Jun 12 '20 15:06 Martinus1

paste me your 2 functions

  1. CellForItemAtIndexPath
  2. WillDisplayCell

patchthecode avatar Jun 12 '20 23:06 patchthecode

 func calendar(_ calendar: JTACMonthView, cellForItemAt date: Date, cellState: CellState, indexPath: IndexPath) -> JTACDayCell {
        var cell = calendar.dequeueReusableJTAppleCell(withReuseIdentifier: "CalendarCell", for: indexPath) as! repeatsCalendarCell
        
        cell = sharedFunctionToConfigureCell(cell: cell, cellState: cellState, date: date)
        self.calendar(calendar, willDisplay: cell, forItemAt: date, cellState: cellState, indexPath: indexPath)
        return cell
    } 

The "startDays" variable consists of the dates that I want to be selected.

func calendar(_ calendar: JTACMonthView, willDisplay cell: JTACDayCell, forItemAt date: Date, cellState: CellState, indexPath: IndexPath) {
        var repeatsCell = cell as! repeatsCalendarCell
        repeatsCell = sharedFunctionToConfigureCell(cell: repeatsCell, cellState: cellState, date: date)
    } 
func sharedFunctionToConfigureCell(cell: repeatsCalendarCell, cellState: CellState, date: Date) -> repeatsCalendarCell {

        cell.dateLabel.text = cellState.text

        if cellState.dateBelongsTo == .thisMonth {
            cell.isHidden = false
        } else {
            cell.isHidden = true
        }
        
  
        var cellConfigured: Bool = false
        
        for date in startDays {
            if Calendar.current.isDate(calendar.startOfDay(for: cellState.date), inSameDayAs: calendar.startOfDay(for: date)) == true {
                cell.isSelected = true
                cellConfigured = true
            }
        }
       
        if cellConfigured == false {
            cell.isSelected = false
        }

        formatter.dateFormat =  "MMM d, yyyy"
        let cellDate = formatter.string(from: cellState.date)
        let today = formatter.string(from: currentDate)
        
        if cellDate == today {
            cell.dateLabel.textColor = #colorLiteral(red: 0.5803921569, green: 0.1294117647, blue: 0.5764705882, alpha: 1)

        } else {
            cell.dateLabel.textColor = #colorLiteral(red: 1, green: 1, blue: 1, alpha: 1)
        }

        
        handleCellConfiguration(cell: cell, cellState: cellState)
        
    
        return cell
    }

Martinus1 avatar Jun 13 '20 12:06 Martinus1

Hey, our app is due to release soon, but this error has been holding our development back. I was responsible for the calendar, and I do not want to switch to another on because I really like this one, so I just wanted to remind you if it would be okej for you to have a look into the functions and identify the error.

Martinus1 avatar Jun 17 '20 17:06 Martinus1

It is something with your code... take my word for this one. you can switch to another lib - and if you shell have another problem? what you going to do? switch to another lib? I think the code here is not sufficient to find the bug - can you upload sample code to debug? do you use the selection function correctly?

calendarView.selectDates(from: range.startDate, to: range.endDate, triggerSelectionDelegate: false, keepSelectionIfMultiSelectionAllowed: true

just few few weeks ago I have used this lib in my project - at last stage I found a bug in this lib - do you think I changed the lib??? after two weeks of work? no... i have just forked this lib with my fix. this is an open source and you are a developer - or aren't you?

alexvaiman avatar Jun 17 '20 18:06 alexvaiman

yes true. @Martinus1 can you do one of 2 things?

Either

  1. Upload a sample app with the bug so i can debug it or
  2. can we chat here? https://gitter.im/patchthecode/JTAppleCalendar

patchthecode avatar Jun 17 '20 23:06 patchthecode