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

The reload() method is not working #12

Closed
absenceofnunchi opened this issue Aug 10, 2020 · 1 comment
Closed

The reload() method is not working #12

absenceofnunchi opened this issue Aug 10, 2020 · 1 comment

Comments

@absenceofnunchi
Copy link

absenceofnunchi commented Aug 10, 2020

The reload() method doesn't retrieve the data from plist. I want the user to input data from one screen and when they visit the screen with the heat map, I want the heat map to reflect the input data. But, the the heat map only reflects the data when the app is loaded for the first time, view.addSubview(calendarHeatMap), but when I use the reload() method any time after, the map doesn't reflect any additional data.

override func viewWillAppear(_ animated: Bool) {
    super.viewWillAppear(animated)
    calendarHeatMap.reload()
}

lazy var calendarHeatMap: CalendarHeatmap = {
    var config = CalendarHeatmapConfig()
    config.backgroundColor = UIColor(ciColor: .white)
    // config item
    config.selectedItemBorderColor = .white
    config.allowItemSelection = true
    // config month header
    config.monthHeight = 30
    config.monthStrings = DateFormatter().shortMonthSymbols
    config.monthFont = UIFont.systemFont(ofSize: 18)
    config.monthColor = UIColor(ciColor: .black)
    // config weekday label on left
    config.weekDayFont = UIFont.systemFont(ofSize: 12)
    config.weekDayWidth = 30
    config.weekDayColor = UIColor(ciColor: .black)
    
    var dateComponent = DateComponents()
    let yearsBefore = -1
    dateComponent.year = yearsBefore
    if let startDate = Calendar.current.date(byAdding: dateComponent, to: Date()) {
        let calendar = CalendarHeatmap(config: config, startDate: startDate, endDate: Date())
        calendar.delegate = self
        return calendar
    } else {
        let calendar = CalendarHeatmap(config: config, startDate: Date(2019, 1, 1), endDate: Date())
        calendar.delegate = self
        return calendar
    }
}()

private func readHeatmap() -> [String: Int]? {
    guard let url = try? FileManager.default.url(for: .documentDirectory, in: .userDomainMask, appropriateFor: nil, create: false).appendingPathComponent("Heatmap.plist") else { return nil }

    return NSDictionary(contentsOf: url) as? [String: Int]
}

Everything else is pretty much the same as the example in this repo.

When the screen is first loaded, the order of execution is:

  1. lazy var calendarHeatMap: CalendarHeatmap
  2. viewWillAppear() which has the calendarHeapmap.reload() method
  3. func readHeatmap()
  4. lazy var data: [String: UIColor]
  5. func finishLoadCalendar()

or

  1. lazy var calendarHeatMap: CalendarHeatmap
  2. func readHeatmap()
  3. lazy var data: [String: UIColor]
  4. func finishLoadCalendar()
  5. viewDidAppear() which has the calendarHeapmap.reload() method

However, when the screen is revisited, none of these are called, except for the view's life cycle methods.

@absenceofnunchi
Copy link
Author

Actually, the issue was the lazy loading of the plist, not anything to do with reloading.

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

1 participant