2017-09-17 74 views
1

fs calendar를 사용하고 있으며 dates라는 배열에서 이벤트 도트를 설정하려고합니다. 이 배열에는 문자열 형식으로 저장된 이벤트 날짜가 있습니다. 그래서 나는 각 인덱스를 날짜로 변환 한 다음 해당 날짜에 대한 이벤트 도트를 설정해야합니다. 여기 그렇게 할 내 시도 :배열에서 fs 캘린더에 이벤트 도트를 표시하는 방법

if dates.isEmpty == false { 
    func calendar(_calendar: FSCalendar!, hasEventForDate dateFormatter: DateFormatter) -> Bool { 
    for i in 0...dates.count - 1 { 
     let dateFormatter = DateFormatter() 
     dateFormatter.dateFormat = "yyyy/MM/dd" 
     dateFormatter.locale = Locale.init(identifier: "fa_IR") 

     dateFormatter.date(from: dates[i]) 

     dateFormatter.dateFormat = "yyyy/MM/dd" 

     return true 
    } 
    return false 

} 
} 

을하지만 아무 일도 발생하지 않습니다와 내가 코드를 컴파일 할 때 어떤 이벤트 도트가 없습니다. 내가 도대체 ​​뭘 잘못하고있는 겁니까?

답변

0

먼저 추천, 당신은 배열의 값을 사용해야하는 경우

둘째은 다음에 대한 를 사용해야합니다 사전에 날짜를 조회 덜 요구하고, 대신에 날짜 배열의 사전을 사용 사용 객체를 직접과,하지 지수는 원래 배열의 개체를 얻을 또한를 사용할 필요가

셋째 번만 날짜 포매터를 선언합니다func calendar(_calendar: FSCalendar!, hasEventForDate dateFormatter: DateFormatter) -> Bool

사용되지 않기 때문에 것은이 코드

func calendar(_ calendar: FSCalendar, numberOfEventsFor date: Date) -> Int { 
    let dateFormatter = DateFormatter() 
    dateFormatter.dateFormat = "yyyy/MM/dd" 
    dateFormatter.locale = Locale.init(identifier: "fa_IR") 

    for dateStr in dates{ 
     if(dateFormatter.string(from: date) == dateStr) 
     { 
      return 1 
     } 
    } 
    return 0 
} 
으로 시도