0

我将 MBCalendar Kit 导入到我的项目中,但我不知道如何在日历中添加事件或事件数组。我找到了这段代码:

NSMutableDictionary *eventsDict = [[NSMutableDictionary alloc] init];

for (int i =0; i< eventsArray.count ;i++)
{

  // Create events
  eventsDict = eventsArray[i];
  CKCalendarEvent* aCKCalendarEvent = [[CKCalendarEvent alloc] init];
  aCKCalendarEvent.title = [eventsDict  objectForKey:@"email"];
  aCKCalendarEvent.date = date; //[eventsArray  objectForKey:@"phone"];
  aCKCalendarEvent.address = [eventsDict  objectForKey:@"addrLine1"];
  aCKCalendarEvent.image = [eventsDict objectForKey:@"pPic"];
  aCKCalendarEvent.name = [eventsDict objectForKey:@"fname"];
  aCKCalendarEvent.appDate = [eventsDict objectForKey:@"apntDt"];
  aCKCalendarEvent.notes = [eventsDict objectForKey:@"notes"];
  aCKCalendarEvent.phone = [eventsDict objectForKey:@"phone"];
  [myeventsArray addObject: aCKCalendarEvent];
}

[_data setObject:myeventsArray forKey:date];

但我不知道在哪里写它,或者如何使用它。谁能帮我?谢谢你。

4

1 回答 1

0

I'm working with this Framework and I've had the same issues.

What worked for me was to use the NSDate+Components category, specifically the dayWithDay:month:year method to create the dates for the events, then create as many events as you want the way you're doing it, encapsulate all the events that are on the same day in an array and lastly setting that array as an object for the NSDictionary data with the previously created as the key to that array. Here's an example:

NSDate *eventDate1 = [NSDate dateWithDay:8 month:8 year:2014];
NSDate *eventDate2 = [NSDate dateWithDay:9 month:8 year:2014];

CKCalendarEvent *event1 = [CKCalendarEvent eventWithTitle:@"Event 1" andDate:eventDate1 andInfo:nil];
CKCalendarEvent *event2 = [CKCalendarEvent eventWithTitle:@"Event 2" andDate:eventDate2 andInfo:nil];

NSArray *today = [NSArray arrayWithObjects:event1, nil];
NSArray *tomorrow = [NSArray arrayWithObjects:event2, nil];

[[self data] setObject:today forKey:eventDate1];
[[self data] setObject:tomorrow forKey:eventDate2];

Hope this helps :D

I'm working on my own framework based on this but with an iOS7 native feel, it's not finished yet but here is the repo:

https://github.com/AndoniV/CalendarBar_iOS7_Style.git

于 2014-08-08T22:06:32.043 回答