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

Changing cell selection results in random cell deselection #1281

Open
Martinus1 opened this issue Jun 12, 2020 · 5 comments
Open

Changing cell selection results in random cell deselection #1281

Martinus1 opened this issue Jun 12, 2020 · 5 comments

Comments

@Martinus1
Copy link

Martinus1 commented Jun 12, 2020

(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 Martinus1 changed the title Changing cell selection results in random cell deselectinon. Changing cell selection results in random cell deselection Jun 12, 2020
@patchthecode
Copy link
Owner

paste me your 2 functions

  1. CellForItemAtIndexPath
  2. WillDisplayCell

@Martinus1
Copy link
Author

Martinus1 commented Jun 13, 2020

 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
Copy link
Author

Martinus1 commented Jun 17, 2020

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.

@alexvaiman
Copy link

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?

@patchthecode
Copy link
Owner

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

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

3 participants