Kompleks zaman çizelgesini girişlerle doldurmak için veriye sahip üç dizim var.Komplikasyon zaman çizelgesini doldurmak için üç diziyi kullanma
Zaman içinde ilerlediğimde, sorun değişmiyor, bu yüzden yanlış bir şey yapmam gerektiğini biliyorum.
func getTimelineEntriesForComplication(complication: CLKComplication, afterDate date: NSDate, limit: Int, withHandler handler: (([CLKComplicationTimelineEntry]?) -> Void)) {
for headerObject in headerArray! {
for body1Object in body1Array! {
for body2Object in body2Array! {
let headerTextProvider = CLKSimpleTextProvider(text: headerObject as! String)
let body1TextProvider = CLKSimpleTextProvider(text: body1Object as! String)
let body2TextProvider = CLKRelativeDateTextProvider(date: body2Object as! NSDate, style: .Offset, units: .Day)
print("HeaderTextProvider: \(headerTextProvider)")
print("Body1TextProvider: \(body1TextProvider)")
print("Body2TextProvider: \(body2TextProvider)")
let template = CLKComplicationTemplateModularLargeStandardBody()
template.headerTextProvider = headerTextProvider
template.body1TextProvider = body1TextProvider
template.body2TextProvider = body2TextProvider
let timelineEntry = CLKComplicationTimelineEntry(date: body2Object as! NSDate, complicationTemplate: template)
entries.append(timelineEntry)
print("TimeEnt: \(entries)")
print("TimeEntCount: \(entries.count)")
}
}
}
handler(entries)
}
Benim düşünce:
- Döngü üç diziler aracılığıyla
body2Array
nesnenin tarihle zaman çizelgesi girişini Set dizinin sonuçları ile şablonu ilmekleri Set
Konsolumdaki çıktı şu şekildedir:
Zamanda yolculuk yolunu çalışmıyor NedenHeaderTextProvider: <CLKSimpleTextProvider: 0x78e3f800>
Body1TextProvider: <CLKSimpleTextProvider: 0x78e4eb30>
Body2TextProvider: <CLKRelativeDateTextProvider: 0x78e4f050>
TimeEnt: [<CLKComplicationTimelineEntry: 0x78e4edd0> date = 2016-03-21 05:00:00 +0000, template = <CLKComplicationTemplateModularLargeStandardBody: 0x78e4edf0>, animationGroup = (null), <CLKComplicationTimelineEntry: 0x78e4f520> date = 2016-10-01 17:00:00 +0000, template = <CLKComplicationTemplateModularLargeStandardBody: 0x78e4f540>, animationGroup = (null)]
TimeEntCount: 2
Bir yana, bahsetmediğim tek şey tarihleri "afterDate" ile karşılaştırmaktır. Diziniz, tarihleri * beforeDate tarihinden önce olabilecek veriler içeriyorsa, bu girişi atlamak ve zaman çizelgesinde döndürmek istemezsiniz. –