Monday 15 August 2011

objective c - How do I Isolate an Event's Title/Time in a variable to display on Storyboard? -



objective c - How do I Isolate an Event's Title/Time in a variable to display on Storyboard? -

here's total description of problem: fetching events of calendar total day (i.e.today) , storing them in array. how isolate next relevant (one has not passed) event's title , time array display them separately labels? here's code:

//load calendar events ekeventstore *store = [[ekeventstore alloc] init]; [store requestaccesstoentitytype:ekentitytypeevent completion:^(bool granted, nserror *error) { if (granted) { nslog(@"user has granted permission"); // appropriate calendar nscalendar *calendar = [nscalendar currentcalendar]; // create start date components nsdatecomponents *begindaycomponents = [[nsdatecomponents alloc] init]; begindaycomponents.day = 0; nsdate *todaystart = [calendar datebyaddingcomponents:begindaycomponents todate:[nsdate date] options:0]; // create end date components nsdatecomponents *enddaycomponents = [[nsdatecomponents alloc] init]; enddaycomponents.day = 0; nsdate *todayend = [calendar datebyaddingcomponents:enddaycomponents todate:[nsdate date] options:0]; // create predicate event store's instance method nspredicate *predicate = [store predicateforeventswithstartdate:todaystart enddate:todayend calendars:nil]; // fetch events match predicate nsarray *events = [store eventsmatchingpredicate:predicate]; nslog(@"here events in array, %@", events); } else { nslog(@"user has not granted permission"); } }];

thanks in advance, , have day!

as apple states in ekeventstore-documentation have sort array first, next pending event @ index 0.

note: retrieving events calendar database not homecoming events in chronological order. sort array of ekevent objects date, phone call sortedarrayusingselector: on array, providing selector comparestartdatewithevent: method.

i'd suggest pick ekevent-object @ index 0 of array , read properties , set them on label.

ekevent *event = [events objectatindex:0]; yourtitlelabel.text = event.text; nsdateformatter *formatter = [[nsdateformatter alloc] init]; formatter.dateformat = @"dd.mm hh:mm"; yourdatelabel.text = [formatter stringfromdate:event.startdate];

edit: sort array events this:

events = [events sortedarrayusingselector:@selector(comparestartdatewithevent:)];

for work, have import eventkit/eventkit.h

objective-c ekevent

No comments:

Post a Comment