JZCalendarWeekView icon indicating copy to clipboard operation
JZCalendarWeekView copied to clipboard

Problems with refreshWeekView() after modify numOfDays

Open aron1127 opened this issue 5 years ago • 6 comments

I have created a button that can control numofDays.

I pressed the button and ran that code.

reloadnumDay += 1
calendarWeekView.numOfDays = reloadNumDay
calendarWeekView.refreshWeekView()

But I did not get the result I wanted.

Initial Screen: first

Result screen: sec

The screen I want: thi

It should start at 1 but start at 2 in the result screen.

I do not know why these results come out. Is there a workaround?

aron1127 avatar May 21 '19 08:05 aron1127

Hi, currently I didn't handle this requirement. Do you want to always keep the same day when you change the numOfDays ?

zjfjack avatar May 22 '19 10:05 zjfjack

Yes. If i adding or subtracting numofDays, I want to keep the same day

aron1127 avatar May 22 '19 10:05 aron1127

What if it is 7 days with firstDayOfWeek?

zjfjack avatar May 23 '19 11:05 zjfjack

I always set it to Monday.

calendarWeekView.setupCalendar(numOfDays: numDay,
                                           shopBookChargeList: self.shopBookChargeListString,
                                           shopBookChargeEmplList: self.shopBookChargeEmplList,
                                           setDate: Date.from(year: 2019, month: 05, day: 01) ?? Date(),
                                           allEvents: AllDayBookModel(),
                                           scrollType: .sectionScroll,
                                           firstDayOfWeek: .Monday)
            
            calendarWeekView.scrollableRange = (Date.from(year: 2019, month: 05, day: 01), Date.from(year: 2019, month: 05, day: shopBookChargeList.count))
            calendarWeekView.updateFlowLayout(JZWeekViewFlowLayout(hourHeight: 80
                , rowHeaderWidth: 50, columnHeaderHeight: 50, hourGridDivision: JZHourGridDivision.minutes_20))

aron1127 avatar May 23 '19 11:05 aron1127

Hi. I've fixed the problem by modifying your library.

I created a numofDaysReload variable in JZBaseWeekView.swift and used it in the updateWeekView() function.

JZBaseWeekView.swift :

public var numOfDays: Int! 
public var numofDaysReload: Int = 1
...

open func refreshWeekView() 
{
    updateWeekView(to: self.initDate.add(component: .day, value: numOfDays + numofDaysReload))
}

In ViewController :

if numofDays += 1
{
    calendarWeekView.numofDaysReload = -1
}
else if numofDays -= 1
{
    calendarWeekView.numofDaysReload = 1
}
calendarWeekView.refreshWeekView()

I do not think it's an efficient method, but it's solved. I am a junior developer in Korea and have poor English and coding skills. Sorry for bothering you. If you see my reply, please close the issue.

aron1127 avatar May 28 '19 02:05 aron1127

Hi,

Thanks for doing it first. I am currently very busy. If I have time in the future and I might give you a better way to achieve this.

Thanks

zjfjack avatar May 29 '19 06:05 zjfjack