Как показать данные о событиях в FSCalander в соответствии с определенным диапазоном дат и дней? - PullRequest
0 голосов
/ 07 июня 2018

Привет, у меня следующий ответ

  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" : [

      ],

Я уже получил данные в виде таблицы, вручную вызвав определенный день.enter image description here

, как показано ниже.

 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).в следующем представлении таблицы ниже.

Пожалуйста, помогите мне, предоставив ясный пример (полный код создан) в соответствии с моим ответом, поскольку я никогда не реализовывал FSCalander.

Заранее спасибо.

1 Ответ

0 голосов
/ 07 июня 2018

шаг 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: $0)})
        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))")
    }
...