【问题标题】:Swift: How to implement CVCalendarSwift:如何实现 CVCalendar
【发布时间】:2016-07-24 09:56:23
【问题描述】:

我正在尝试实现 CVCalendar cocoapod (https://github.com/Mozharovsky/CVCalendar),并在说明中说:

'CVCalendar 需要实现两个协议 CVCalendarViewDelegate 和 CVCalendarMenuViewDelegate,请同时实现。'

我不明白该怎么做。

【问题讨论】:

    标签: ios swift cocoapods protocols


    【解决方案1】:

    您只需要将您的类设为 CVCalendarViewDelegate 和 CVCalendarMenuViewDelegate 的子类。

    class ViewController: UIViewController, CVCalendarViewDelegate, CVCalendarMenuViewDelegate {
    

    文档:https://developer.apple.com/library/ios/documentation/Swift/Conceptual/Swift_Programming_Language/Inheritance.html#//apple_ref/doc/uid/TP40014097-CH17-ID195

    看看这个问题的答案:Conform to protocol in ViewController, in Swift

    【讨论】:

      【解决方案2】:

      根据 Oliver 的回答,您需要在类声明中添加协议:

      class ViewController: UIViewController,CVCalendarMenuViewDelegate,CVCalendarViewDelegate {
      

      您还需要添加这两个函数以符合新协议:

      func presentationMode() -> CalendarMode{
          return .monthView
      }
      func firstWeekday() -> Weekday{
          return .monday
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2015-02-22
        • 2015-11-30
        • 2014-09-07
        • 2016-11-27
        • 2017-04-30
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多