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

Bug on mutiple selection #64

Closed
victtavares opened this issue Jul 6, 2016 · 16 comments
Closed

Bug on mutiple selection #64

victtavares opened this issue Jul 6, 2016 · 16 comments

Comments

@victtavares
Copy link

Hi,

It will be hard to explain it in english, but I will give a try ;P.

I have a application with a filter on the top in which I can select a whole week for example, I also have 2 buttons on the top in which I can go to the next week or to the previous week. Here is my screen:

Default Screen

In order to to go to the previous week or to the next week, I deselect the current selected week and select the next one, everything works fine when I press the buttons slowly. However, we I press the next or the previous repeatedly, at some point, the selector become crazy, and I lost the reference of the weeks, or it gives an weird crash (fatal error: Index out of range).

The crash breakpoint:
screen shot 2016-07-06 at 11 30 13 am

And the crazy selection (It should be selecting from 10-16, but it's not selecting the 12, and selecting the 17):
slack for ios upload-1

Here is my code:

    @IBAction func calendarPreviousButtonPressed(sender: AnyObject) {

        //an array with the last selected dates
        var referenceDate = currentSelectedDates.getElement(0)!
        unselectSelectedDates()

        //An enum that indicates the current filter been applied.
        switch currentDateFilter {
        case .monthly:
            referenceDate = referenceDate.sameDayOnMonth(-1)
            currentSelectedDates = referenceDate.daysOnThisMonth()
        case .weekly:
            //returns the same day of the week, from the next week, for example if today is 01/07/2016, it will returns the 08/07/2016
            referenceDate = referenceDate.sameDayOnWeek(-1)
            //returns an array with all the dates from the current week.
            currentSelectedDates = referenceDate.daysOnThisWeek()
        case .today:
            changeDateFilter(.day)
            currentSelectedDates = [referenceDate]
        case .day:
            referenceDate = referenceDate.addDay(-1)
            currentSelectedDates = [referenceDate]

        }


        self.calendarView.scrollToDate(self.currentSelectedDates[0], animateScroll: true) {
            [unowned self] in
            self.calendarView.selectDates(self.currentSelectedDates, triggerSelectionDelegate: true)
        }

    }

The unselectSelectedDates function:

    func unselectSelectedDates() {
        let selectedDates = self.calendarView.selectedDates
        calendarView.selectDates(selectedDates)
    }

After further investigation, I figured out that the unselect and selection delegate methods, are called asynchronously, and it could be causing the problem, but I couldn't find a easy solution for that, do you have any ideas?

@patchthecode patchthecode self-assigned this Jul 6, 2016
@patchthecode
Copy link
Owner

looking into it now.

@patchthecode patchthecode added bug and removed question labels Jul 6, 2016
@patchthecode
Copy link
Owner

patchthecode commented Jul 6, 2016

One thing, you do have calendarView.allowsMultipleSelection = true right?

Can you show me your viewDidLoad() calendar setup code?

@victtavares
Copy link
Author

Yep!

override func viewDidLoad() {
        super.viewDidLoad()
        configureCalendar()
        configureHeader()
        configureTableView()
        configureCalendarHeader()
        createDateFilterPicker()

    }

I setup the calendar on the configureCalendar method.

    func configureCalendar() {
        calendarView.dataSource = self
        calendarView.delegate = self
        self.calendarView.registerCellViewXib(fileName: "DateCellView")
        calendarView.cellInset = CGPoint(x: 0, y: 0)
        calendarView.allowsMultipleSelection = true
    }

I can't share the whole project, but if you need any part of the code just let me know!

@victtavares
Copy link
Author

Hi @patchthecode, could you simulate the bug? If you need any help just let me know. 👍

@patchthecode
Copy link
Owner

Sorry I didnt get back to you.
Yes. I have simulated it. I am currently working on a fix. A new release should be ready over the weekend 4.1.1

But I will be pushing the fix to the master branch today. I'll let you know once I do the push so that you can check to see if the fix works before i do the release. Sounds good? :]

@victtavares
Copy link
Author

Perfect! I'm pretty curious to know what was the problem and the solution for that!

Sure! As soon as you push your solution I will test it on my side. Could you share the project that you are using to simulate this bug?

@patchthecode
Copy link
Owner

The sample project I am using to simulate it is the sample project here on github.
https://github.com/patchthecode/JTAppleCalendar.git

I havent pushed the changes yet though. And as for the bug simulation, I no longer see the bug on my end. One sec, let me send you the zip file of my local sample project. I'm just wrapping up some other code parts form it.

@patchthecode
Copy link
Owner

7 hrs later.. still working on it. When I push it today, i'll let you know

@victtavares
Copy link
Author

Thank you for the hard work and the constant feedbacks @patchthecode!

@patchthecode
Copy link
Owner

Do you know how to test the master branch code?
I have pushed the code to the master branch.

@victtavares
Copy link
Author

I think so, I'm using cocoapods, so I did this:
pod 'JTAppleCalendar', :git => 'https://github.com/patchthecode/JTAppleCalendar.git'

I think its using the current master branch. Testing it.. :)

@victtavares
Copy link
Author

Everything is working fine here! Thank you @patchthecode! What was the bug? I see now that the deselection always happens before the selection, it was kind of random before.

@patchthecode
Copy link
Owner

if you do a deselection before a selection, then the deselection should always happen before the selection.
if you do a selection before a deselection, then the selection should always happen before the deselection.

nothing should be random.

if you encounter anything weird like that again, even if it is a tiny tiny tiny issue, then please let me know.
Every thing should work perfectly with this library. I want no bugs.

The multi-selection bug was occurring because of an error i had in the desselection process.
It was in the closure let deSelectTheDate = { (oldIndexPath: NSIndexPath) -> Void in

i was deselecting the indexPath that the user wanted to select instead of the oldIndexPath that should have been deselected. I used the wrong variable name (index vs oldIndex). It must have been late that night when i did that code set.

@patchthecode
Copy link
Owner

patchthecode commented Jul 9, 2016

by the way, i put in a new function because of you,
selectDates(from startDate:NSDate, to endDate:NSDate, triggerSelectionDelegate: Bool = true)

and yes, your English is perfect 👍
Also, your calendar looks nice, do you mind inspiring others with it by posting an image here? ->> https://github.com/patchthecode/JTAppleCalendar/issues/2

I'll do the official release sometime later. cheers

@victtavares
Copy link
Author

Thank you! This new function will be really useful!
I still need to work on some small changes on the calendar, but as soon as I finish it, I will post it. :]

Good work on this calendar! it's very flexible and provides a lot of good built-in functionalities. I will recommend it for sure!

@patchthecode
Copy link
Owner

Thanks! closing this issue. will make an official release soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants