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

Scrolling Problem - Cells give wrong information #779

Closed
aliihsanural opened this issue May 11, 2018 · 15 comments
Closed

Scrolling Problem - Cells give wrong information #779

aliihsanural opened this issue May 11, 2018 · 15 comments

Comments

@aliihsanural
Copy link

aliihsanural commented May 11, 2018

Hi,

I try to catch cells information. In viewDidLoad(), calendar loads dates and prints correct days in handleCellEvents() . But when i scroll the calendar right or left , this prints() doesnt print correct dates. The prints start at the end of the week or start of the week and goes on forward or backward not show the seen dates . Also I try to implements evets week by week .

Is it a bug or my mistake ?

screen shot 2018-05-11 at 10 45 32

func handleCellEvents(cell: CustomCalendarCell, cellState: CellState) {
    
    formatter.dateFormat = "yyyy MM dd"
    print("handle Cell: \(formatter.string(from: cellState.date)) " )
    cell.eventDotView.isHidden = !eventsFromTheServer.contains { $0.key == formatter.string(from: cellState.date)
    
    }
}
@patchthecode
Copy link
Owner

I am not understand what the problem is.

Can you tell me

  1. what is the expected date you want to see when scrolling?
  2. what is the incorrect date that you are seeing?

@aliihsanural
Copy link
Author

aliihsanural commented May 11, 2018

1 - I expect to get the days of the week which is seen in calendar. Because I want to call the events of the shown days. How I do that ? I have to catch these days and send to server .

2 - For Example When I scroll to right side, I catch the dates

In cellForItemAt
CellForDate 2018-05-13 21:00:00 +0000
CellForDate 2018-05-14 21:00:00 +0000
CellForDate 2018-05-15 21:00:00 +0000
CellForDate 2018-05-16 21:00:00 +0000
CellForDate 2018-05-17 21:00:00 +0000
CellForDate 2018-05-18 21:00:00 +0000
CellForDate 2018-05-19 21:00:00 +0000
CellForDate 2018-05-20 21:00:00 +0000
CellForDate 2018-05-21 21:00:00 +0000
CellForDate 2018-05-22 21:00:00 +0000
CellForDate 2018-05-23 21:00:00 +0000
CellForDate 2018-05-24 21:00:00 +0000
CellForDate 2018-05-25 21:00:00 +0000

In handleCellEvents func
handle Cell: 2018 05 14
handle Cell: 2018 05 15
handle Cell: 2018 05 16
handle Cell: 2018 05 17
handle Cell: 2018 05 18
handle Cell: 2018 05 19
handle Cell: 2018 05 20
handle Cell: 2018 05 21
handle Cell: 2018 05 22
handle Cell: 2018 05 23
handle Cell: 2018 05 24
handle Cell: 2018 05 25
handle Cell: 2018 05 26

How I call week's events from this situation ?

@patchthecode
Copy link
Owner

patchthecode commented May 11, 2018

This library is a UICollectionView subclass. You cannot depend on the cellForItemAt function to give you dates that are visible on the screen. Apple has the UICollectionView coded efficiently and it will only show new dates as determines by the UICollectionView. We do not have control over this.

If you want to capture visible dates when you scroll, can you use the following function?

func calendar(_ calendar: JTAppleCalendarView, didScrollToDateSegmentWith visibleDates: DateSegmentInfo) {
   // use the `visibleDates` variable here. It will tell you which dates are visible on the screen with each scroll
}

Let me know if this helps

@KrishNaveen
Copy link

KrishNaveen commented May 11, 2018

I tried the above function you suggested it works fine. But I still can see the problem where I tap twice quickly then I am having the issue of seeing old title(Note: Collection view is working as expected)

@aliihsanural
Copy link
Author

@patchthecode didScrollToDateSegmentWith functions starts from Sunday and it starts to show one day before.
Note: I configure calendar with "firstDayOfWeek: DaysOfWeek = .monday"

@aliihsanural aliihsanural changed the title Scrolling Problem - Cells give wring information Scrolling Problem - Cells give wrong information May 11, 2018
@patchthecode
Copy link
Owner

didScrollToDateSegmentWith functions starts from Sunday and it starts to show one day before.
Note: I configure calendar with "firstDayOfWeek: DaysOfWeek = .monday"

Can you explain this more?
Hey, I cannot know what the problem is if you just tell me the problem.
You need to tell me

  1. What you are seeing
  2. What you were expecting

Only then i can know the difference between what you are seeing and what you are expecting.

@aliihsanural
Copy link
Author

aliihsanural commented May 11, 2018

You can see the picture at the top that shows firstday is Monday 7 , May. But when i run this code
print("Visible dates : (visibleDates.monthDates)") in "didScrollToDateSegmentWith" , it shows

Visible dates : [
(date: 2018-05-06 21:00:00 +0000, indexPath: [19, 6]), 
(date: 2018-05-07 21:00:00 +0000, indexPath: [20, 0]), 
(date: 2018-05-08 21:00:00 +0000, indexPath: [20, 1]), 
(date: 2018-05-09 21:00:00 +0000, indexPath: [20, 2]),
(date: 2018-05-10 21:00:00 +0000, indexPath: [20, 3]), 
(date: 2018-05-11 21:00:00 +0000, indexPath: [20, 4]), 
(date: 2018-05-12 21:00:00 +0000, indexPath: [20, 5])]

It starts 2018-05-06 21:00:00 +0000 but i want that 7. The problem is this.

@patchthecode
Copy link
Owner

Ok i understand the problem now.
Can you let me know how you are printing the dates to console?

I believe that your problem is this --> #252

It maybe by due to how you are printing the data.
Read the issue and let me know if it makes sense to you.

@aliihsanural
Copy link
Author

Hi again, I think is not a same problem with #252 because that is time zone problem but i get the days wrongly.

func calendar(_ calendar: JTAppleCalendarView, didScrollToDateSegmentWith visibleDates: DateSegmentInfo) {
    print("Visible dates : \(visibleDates.monthDates)")
    setupViewsOfCalendar(from: visibleDates)
}

Today 2018-05-14

With this function Print is :
Visible dates : [(date: 2018-05-13 21:00:00 +0000, indexPath: [20, 6]), (date: 2018-05-14 21:00:00 +0000, indexPath: [21, 0]), (date: 2018-05-15 21:00:00 +0000, indexPath: [21, 1]), (date: 2018-05-16 21:00:00 +0000, indexPath: [21, 2]), (date: 2018-05-17 21:00:00 +0000, indexPath: [21, 3]), (date: 2018-05-18 21:00:00 +0000, indexPath: [21, 4]), (date: 2018-05-19 21:00:00 +0000, indexPath: [21, 5])]

I guess i get these days with +1 Day. No other solution come to my mind.

@patchthecode
Copy link
Owner

can you paste me your configureCalendar function?
I need to see how you have setup your calendar.

@aliihsanural
Copy link
Author

Day Times starts from 21:00 . Is it possible about timezone ? I am in GMT+3.

  formatter.dateFormat = "yyyy MM dd"
        
        let timeZone = TimeZone(identifier: "Europe/Amsterdam")
        formatter.timeZone = timeZone
        //formatter.timeZone = TimeZone(secondsFromGMT: 10800)
        formatter.locale = Calendar.current.locale
        
        let startDate = formatter.date(from: "2018 01 01 ")
        let endDate = formatter.date(from: "2018 12 31 ")
        
        let generateInDates: InDateCellGeneration = .off
        let generateOutDates: OutDateCellGeneration = .off
        let firstDayOfWeek: DaysOfWeek = .monday
        let hasStrictBoundaries = false
        let testCalendar = Calendar.current
        
        let parameters = ConfigurationParameters(startDate: startDate!,
                                                 endDate: endDate!,
                                                 numberOfRows: 1,
                                                 calendar: testCalendar,
                                                 generateInDates:  generateInDates ,
                                                 generateOutDates: generateOutDates,
                                                 firstDayOfWeek: firstDayOfWeek,
                                                 hasStrictBoundaries: hasStrictBoundaries
        )
        
        
        return parameters

@patchthecode
Copy link
Owner

i believe your problem is time zone issue, because your dates are one day off.

can you try printing your dates to the console like this --> #252 (comment) ?

@patchthecode
Copy link
Owner

patchthecode commented May 15, 2018

Basically the answer is that you should not just print your dates to console like the way you did.
Because by default, it will print a timeZone based in the USA where Apple's head quarters is.

If you want to print the correct dates to the console, you must use a date formatter.
Because if you do not put one, the iOS framework will put one for you -->> A USA timeZone.
This same problem happens in any iOS Calendar framework on github you find.

One clue that makes me think the problem is timezone, is this -->
The Dates displayed on your calendar is correct.
But
The dates printed to the console is one +1 day wrong.

@patchthecode
Copy link
Owner

patchthecode commented May 20, 2018

Hey, the best thing to resolve this would be a sample app.
Can you send me a zipped copy of a sample project with the issue?
If i i have a sample project, then i can fix the issue faster.

send to patchthecode@gmail.com and let me know once you do so.

@aliihsanural
Copy link
Author

Its about TimeZone . Its not a bug. Thank you for all replies

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

3 participants