CVCalendar DayView.date错误

时间:2015-07-28 13:11:18

标签: ios xcode swift github calendar

我使用GitHub的Mozharovsky的CVCalendar。 我尝试使用此方法标记特定日期:

 <div>
   <input type="text" class="ip_text"  placeholder="Name" th:field="${user.Name}"/>
  </div>
  </div>
  <div>
  <input type="email" class="ip_text"  placeholder="Email ID" required="true" th:field="${user.email}"/>
  </div>
  </div>
  <div class="phone_nm">
  <span class="p_code">+91</span>
  <input type="text" class="ip_text" pattern="^([0-9]{10})?$"
  required="true" th:field="${user.phoneNumber}"/>
  </div>
  </div>


  remove lots of thing to make it simple
  Href:: 

  <a th:href="@{'https://www.instamojo.com/stayuncle/payments-for-stayuncle/?data_amount='+${ hotel.totalPrice + hotel.serviceTaxTotal + hotel.vatTotal }+'&amp;'+'data_name='+${user.Name}+'&amp;'+'data_email='+${user.email}+'&amp;'+'data_phone='+${user.phoneNumber}}" rel="im-checkout" data-behavior="remote"  data-token="059542XXXXXXXXXXX3165a40a" class="button pay_now">pay now</a>

问题是dayView.date有时会导致错误:

func supplementaryView(shouldDisplayOnDayView dayView: DayView) -> Bool
{
    if(dayView.date.day == day && dayView.date.month == month) {
        return true
    }

    return false
}

如何避免犯罪和错误?

1 个答案:

答案 0 :(得分:0)

只需使用基本的可选展开来测试它是否已定义并做适合您需求的内容:

func supplementaryView(shouldDisplayOnDayView dayView: DayView) -> Bool
{
    if let date = dayView.date {
        if(date.day == day && date.month == month) {
            return true
        }
    } else {
        // date is nil :(
    }

    return false
}