Closed patchthecode closed 8 years ago
Ok let me understand. Tell me which part below is wrong:
Ok i think i understand your problem. This is the behavior of multi selection. If multi-select is enabled, and you select a date on the screen. That date will be selected. If you select that same date again, the selection will disappear.
Did you want the date to remain selected after tapping it again?
If you think this is a bad behavior then lets talk about it :)
From the screenshot you provided of your calendar, here is what i am guessing. (my guess could be wrong, but here goes)
You have some dates saved, and you want the background of the saved dates so show color yellow right? So you enabled multiselection, and had those dates selected as yellow right?
Well this i not the right way to do it. Selection is for Selection and should mean Selection - i.e. A User selected a date. What you want is not selection. What you want is a new state.
Lets call this state: PreviouslySavedDate
This is the beauty of JTAppleCalendar, you can make up anything you want. The power is in the hands of the developer. The following example is based on the sample code i have here in github. Head over to CellView.swift and write up your own code to handle how a SavedDate state will look.
Your code can be something like this:
If myDate == aDateThatExistsInMySavedDateArray { // In other words, a PreviouslySavedDate
// Make my PreviouslySavedDateBackView color to be yellow and set its `.Hidden` property to be false.
// Dont have a PreviouslySavedDateBackView on your cellView.xib? easy, just create one.
// You can create anything you want on cellview.xib.
} else {
// Hide my PreviouslySavedDateBackView by making `.Hidden` property = true
}
Hey,
But what if I want to deselect/erase previously selected day? If I only change background and not isSelected = true, then I would't be able to tap on it to delete it, wouldn't I?
Basically I want to be in sync every second because when user taps on a date it is saved on Firebase, when taps again on a date that has isSelected = true then it is deselected, erased from Firebase and that new array of dates is downloaded again, previous array is emptied and filled with new fresh values that are displayed on calendar.
I see what you are saying. But one thing. This multiple selection behavior is not some thing i made up. This is Apple's behavior of multiple selection. You can see in their documentation here:
If i change the way it behaves then this will be changing the way it behaves for many users that expect it to behave like this. So maybe you need to architecture your code differently?
So here is a question for you: From what you've said, selection happens when a user taps the cell right? So can you tell me how you want to have deselection happen?
The thing is that I use Firebase that has a function which trigers code when I make a change in my Firebase. I am making changes as user taps on a date. If I tap on a date which is not previously selected it will upload that date (string value) into Firebase. If I deselect that date it will delete that date from Firebase. Every time these changes are happening one block of code is repeated. In that block of code is .selectDates() function. So when I run my app everything is okay, dates are populated. But when I want to add a date (tapping on it) then .selectDates() runs one more time and deselects all my dates. The same thing happens if I deselect previously selected date. I'm starting to think this is not posible the way I wanted to.
UPDATE:
I managed to find a workaround for my problem. Now it works. Finally!
Awsome. Closing this issue :)
The allowsMultipleSelection is not in the documentation anymore. :/
@vital-edu i do not understand what you mean?
Its documented on Apple's Site for UICollectionViews. Let me know.
I am sorry. I didn't notice that the calendar is a UICollectionViews.
Its cool. cheers 🍺
Pasted from user:
It's me again.
This new function is working in a weird way. Let me show you. When the app first loads it runs this:
calendarView.selectDates(selectedDays, triggerSelectionDelegate: false)
And this works as expected, my dates get isSelected to true. Then, when I tap on a date to select it or deselect it that code is repeated, but instead of selecting every date in my array again it sets their isSelected property to false and they disappear.
tried to play with it a little and I typed:
calendarView.selectDates(selectedDays, triggerSelectionDelegate: false) // makes dates in array selected
calendarView.selectDates(selectedDays, triggerSelectionDelegate: false) // this one destroys work of that previous one
That second function really reverts their state to the opposite of their previous state. Why is that happening?