簡體   English   中英

快速獲取api響應時如何重新加載CVCalendar

[英]How to reload CVCalendar when getting api response in swift

我正在使用CVCalendar顯示帶有事件的日歷。 但是事件是從其余的 api call 加載的。 收到回復后,我無法更新日歷中的事件。

我以前從未使用過該庫,但環顧 API,在不同的類中有各種“重新加載”方法。 如果您查看演示項目, CVCalendarMonthContentViewController視圖控制器有一個方法reloadMonthViews 我建議你看看那個,以及視圖類中的重新加載方法。

根據過多的搜索,我發現了這行神奇的代碼,它對我有用 在 CVCalendarView 中的函數下方使用,並將NSDate()作為參數傳遞

public func reloadMonthView(selectedDate: NSDate) {
            let newController: ContentController

            contentController.updateHeight(contentController.presentedMonthView.potentialSize.height, animated: true)
            newController = MonthContentViewController(calendarView: self, frame: bounds, presentedDate: selectedDate)

            newController.updateFrames(bounds)
            newController.scrollView.alpha = 0
            addSubview(newController.scrollView)

            UIView.animateWithDuration(0.5, delay: 0, options: UIViewAnimationOptions.CurveEaseInOut, animations: {
                self.contentController.scrollView.alpha = 0
                newController.scrollView.alpha = 1
                }) { _ in
                    self.contentController.scrollView.removeAllSubviews()
                    self.contentController.scrollView.removeFromSuperview()
                    self.contentController = newController
            }
    }

你可以嘗試以下方式

self.calendarView.contentController.refreshPresentedMonth()

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM