如何从EKEvents获取Exact事件?

时间:2016-12-02 12:14:14

标签: ios objective-c ekevent

我可以访问模拟器日历中的所有活动。 array看起来很丑陋。

我的代码是,

(void)viewDidLoad {

    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    NSCalendar *calendar = [NSCalendar currentCalendar];

    EKEventStore *eventStore = [[EKEventStore alloc]init];

    NSDateComponents *oneDayAgoComponents = [[NSDateComponents alloc] init];
    oneDayAgoComponents.day = -1;
    NSDate *oneDayAgo = [calendar dateByAddingComponents:oneDayAgoComponents toDate:[NSDate date] options:0];

    // Create the end date components
    NSDateComponents *oneYearFromNowComponents = [[NSDateComponents alloc] init];
    oneYearFromNowComponents.month = 1;
    NSDate *oneYearFromNow = [calendar dateByAddingComponents:oneYearFromNowComponents toDate:[NSDate date] options:0];

    // Create the predicate from the event store's instance method
    NSPredicate *predicate = [eventStore predicateForEventsWithStartDate:oneDayAgo endDate:oneYearFromNow calendars:nil];

    // Fetch all events that match the predicate
    NSArray *events = [eventStore eventsMatchingPredicate:predicate];

    NSLog(@"The content of array is%@",events);


}

我的输出是

enter image description here

我的问题是

我怎样才能显示突出显示的字符串(显示图像),这就是我可以在table view cell上显示的内容。

提前致谢

1 个答案:

答案 0 :(得分:0)

EKEventEKCalendarItem的后代,因此您可以致电event.title获取该属性。