2

您好 JTAppleCalendar 中的 newBiew。我已经关注此链接以创建基于 JTAppleCalendar 的日历。 https://www.youtube.com/watch?v=CQNotydm58s&index=6&list=PLpqJf39XekqyUG7dxcqGO0JNprryysv9Q

在用户按下日历上的日期后,我无法弄清楚如何获取日期。

这里的代码:
在didSelectDate中。日期返回总是晚一天??

这就是我想要实现的。当用户点击日历上的日期时,我想获取日期并使用此日期从服务器请求数据,

extension MyCalendar: JTAppleCalendarViewDataSource, JTAppleCalendarViewDelegate {

    func configureCalendar( _ calendar:JTAppleCalendarView) ->ConfigurationParameters{

        formatter.dateFormat = "yyyy MM dd"
        formatter.timeZone = Calendar.current.timeZone
        formatter.locale = Calendar.current.locale

        let startDate = formatter.date(from: "2017 01 01")!
        let endDate = formatter.date(from: "2027 12 31")!        

        let parameters = ConfigurationParameters(startDate : startDate, endDate: endDate)          
        return parameters

    }


  func calendar( _ calendar: JTAppleCalendarView, cellForItemAt date: Date, cellState: CellState, indexPath: IndexPath) -> JTAppleCell{


        let cell = calendar.dequeueReusableJTAppleCell(withReuseIdentifier: "CustomCell", for: indexPath) as! CustomCell

        cell.dateLabel.text = cellState.text

        configureCell(cell:cell, cellState: cellState)

        return cell

    }


    //------------ selected item

    func calendar( _ calendar: JTAppleCalendarView, didSelectDate date: Date, cell:JTAppleCell?, cellState:CellState){

        // cell is option
        configureCell(cell: cell, cellState: cellState)

       //prolem:
        let strdate = cellState.date

    }


    func calendar( _ calendar: JTAppleCalendarView, didDeselectDate date: Date, cell:JTAppleCell?, cellState:CellState){

        // cell is option
        configureCell(cell: cell, cellState: cellState)

    }

   func calendar(_ calendar: JTAppleCalendarView, didScrollToDateSegmentWith visibleDates: DateSegmentInfo) {

       setupCalendarView(dateSegment: visibleDates)

    }

}

请帮忙,

谢谢

4

1 回答 1

1

答案在这个 github 问题中找到。永远不要查看 xcode 控制台来查看正确的日期。日期的打印命令和 XCode 显示都有自己的格式,可能与您的时区不同。由于格式错误,您仅在视觉上看到的日期“看起来”不正确。要在 iOS 中正确显示日期,请始终使用 DateForamatter。我在上面发布的链接为您解释了它。这个问题存在于您使用的任何 iOS 日历库中。

于 2017-11-08T14:53:22.393 回答