objective-c - 如何使用EventKit Framework提前一年设置提醒

标签 objective-c ios cocoa-touch eventkit

我试图在使用Eventkit Framework添加事件时将开始日期提前1年。

到目前为止,我已经看过了,做了谷歌搜索并尝试了

controller.event.startDate = [[[NSDate alloc] initWithTimeInterval: 525960];
controller.event.endDate= [[NSDate alloc] init];

我收到一条错误消息NSDate declares the selector initWithTimeInterval

最佳答案

不要这样做,因为interval = 525960。

而是使用NSCalender,然后通过将1加到当前年份进行操作。

NSCalendar *calendar=[[NSCalendar alloc] initWithCalendarIdentifier: NSGregorianCalendar] ;
NSDateComponents *components=[[NSDateComponents alloc] init] ;
components.year=1;
NSDate *newDate=[calendar dateByAddingComponents: components toDate:[NSDate date] options: 0];
NSLog(@"Next year : %@", newDate);

关于objective-c - 如何使用EventKit Framework提前一年设置提醒,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14110979/

相关文章:

cocoa-touch - 在 UITableView 中对齐图像

objective-c - obj-c中连续按下按钮时如何重复执行某个 Action

ios - cellForRowAtIndexPath NSRangeException

ios - 通用链接(深度链接)不适用于 iPhone 但适用于 iPad

iPhone+后台执行选择器

ios - 如何在自定义 View 中将 subview 的框架设置为其父框架

ios - CAMediaTiming中的kCAFillModeRemoved和CAAnimation的removedOnCompletion属性之间的区别

ios - Objective-C:单步执行 double* 数组时 EXC_BAD_ACCESS code=2

objective-c - 如何从nsarray删除空格,方括号和“

ios - 在 Swift 中将 CLLocation 转换为 MKMapItem