0
下面是我的問題的完整描述:我將日曆的事件提取一整天(即今天)並將它們存儲在一個數組中。如何從數組中隔離下一個相關(未傳遞的)事件的標題和時間,以將它們分別顯示爲標籤? 這裏是我的代碼:提前如何在變量中顯示事件的標題/時間以顯示在故事板上?
//Load Calendar Events
EKEventStore *store = [[EKEventStore alloc] init];
[store requestAccessToEntityType:EKEntityTypeEvent completion:^(BOOL granted,
NSError *error) {
if (granted) {
NSLog(@"User has granted permission");
// Get the appropriate calendar
NSCalendar *calendar = [NSCalendar currentCalendar];
// Create the start date components
NSDateComponents *beginDayComponents = [[NSDateComponents alloc] init];
beginDayComponents.day = 0;
NSDate *todayStart = [calendar dateByAddingComponents:beginDayComponents
toDate:[NSDate date]
options:0];
// Create the end date components
NSDateComponents *endDayComponents = [[NSDateComponents alloc] init];
endDayComponents.day = 0;
NSDate *todayEnd = [calendar dateByAddingComponents:endDayComponents
toDate:[NSDate date]
options:0];
// Create the predicate from the event store's instance method
NSPredicate *predicate = [store predicateForEventsWithStartDate:todayStart
endDate:todayEnd
calendars:nil];
// Fetch all events that match the predicate
NSArray *events = [store eventsMatchingPredicate:predicate];
NSLog(@"Here are the events in the array, %@", events);
} else {
NSLog(@"User has not granted permission");
}
}];
感謝,並有一個美好的一天!
謝謝!你能告訴我一個如何按日期對數組中的事件進行排序的例子嗎?我仍然是新的。但是,再次,謝謝! – 2014-10-17 22:00:01
我已將它添加到我的答案中,請看一看。 – TMob 2014-10-20 10:14:35