iosxcodeios7calendarmbcalendarkit

Create Events for MBCalendarKit in iOS


I imported MBCalendar Kit into my project, and I don't know how to add an event or array of events in calendar. I found this code:

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];

but I don't know where to write it, or how to use it. Can anyone help me? Thank you.


Solution

  • 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