如何根据特定日期和日期范围在 FSCalander 中显示事件数据?

How to show the events data in FSCalander according to particular date and days range?

您好,我有以下回复

  json: {
  "status" : "success",
  "data" : {
    "classes" : {
      "SUNDAY" : [
        {
          "latitude" : 32.3844785674545,
          "uploads" : "https:\/\/xxxxx\/Uploads\/Class\/swimming.png",
          "location" : "dubai",
          "id" : 3,
          "startDate" : "04-08-2018",
          "endDate" : "05-08-2018",
          "description" : "Basic Swimming Tactics for women trained by women.",
          "title" : "Swimming Class",
          "endTime" : "05:20",
          "longitude" : 23.465767967087778,
          "startTime" : "03:10",
          "subTitle" : "Basic Swimming Tactics"
        }
      ],
      "WEDNESDAY" : [

      ],
      "THURSDAY" : [

      ],

我已经通过手动调用特定日期获取了 tableview 中的数据。

如下。

 func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
     //   return tableViewImageArray.count
        return classes.count
    }

    // Table View Delegates
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {


        let tCell = tableView.dequeueReusableCell(withIdentifier: "schedulesCell", for: indexPath) as! schedulesTVCell
       // tCell.classThumb.image = tableViewImageArray[indexPath.row]
       // tCell.classTitle.text = classNameArray[indexPath.row]
        let allClasses = classes[indexPath.row]
        tCell.classTitle.text = allClasses.title
        tCell.classDesc.text = allClasses.description
        tCell.classLocation.text = allClasses.location

        let cImgUrl = allClasses.uploadURL

        //make the thumb image round
        tCell.classThumb.layer.borderWidth = 1
        tCell.classThumb.layer.masksToBounds = false
        tCell.classThumb.layer.borderColor = UIColor.lightGray.cgColor
        tCell.classThumb.layer.cornerRadius = tCell.classThumb.frame.height/2
        tCell.classThumb.clipsToBounds = true


        Alamofire.request(cImgUrl).responseData(completionHandler: { response in
            if let image1 = response.result.value {
                self.thumbImage = UIImage(data: image1)!
                tCell.classThumb.image = self.thumbImage
                print("IMG", self.thumbImage! )

            }
        })

        return tCell;
    }

我只想根据我在特定日期范围(startDate 和 EndDate)之间单击的日期加载 tableview。在下面的表格视图中。

请根据我的回复提供一个清晰的示例(已提供完整代码)来帮助我,因为我从未实现过 FSCalander。

提前致谢。

步骤 1)

 @IBOutlet var calender: FSCalendar!

步骤 2)

    calender.select(Date())
    calender.scope = .week
    calender.accessibilityIdentifier = "calender"

步骤 3)

  callApiWillGiveresultbasedonselectedDate(currentselectedDate:String)

基于表视图中显示的 api 数组响应 在每次 api 调用时重新加载

步骤 4)

//MARK: - Calender Method
    func calendar(_ calendar: FSCalendar, boundingRectWillChange bounds: CGRect, animated: Bool) {
        self.calendarHeightConstraint.constant = bounds.height
        self.view.layoutIfNeeded()
    }

    func calendar(_ calendar: FSCalendar, didSelect date: Date, at monthPosition: FSCalendarMonthPosition) {
        let selectedDates = calendar.selectedDates.map({self.dateFormatter.string(from: [=13=])})
        print("selected dates is \(selectedDates)")
        currentselected = "\(self.dateFormatter.string(from: date))"
        callApiWillGiveresultbasedonselectedDate(currentselectedDate: currentselected)
        if monthPosition == .next || monthPosition == .previous {
            calendar.setCurrentPage(date, animated: true)
        }
    }

    func calendarCurrentPageDidChange(_ calendar: FSCalendar) {
        print("\(self.dateFormatter.string(from: calendar.currentPage))")
    }