如何以编程方式选择事件工具包日历的日期/时间和标题

时间:2012-03-05 23:19:20

标签: xcode eventkit

以下是我的代码。当前在按钮上单击它会打开日历,以便用户可以添加事件。当事件日历打开时,如何为用户传递或预选日期和标题?

继承我的代码。

 -(IBAction) createEvent{
EKEventStore *eventStore = [[EKEventStore alloc] init];

EKEventEditViewController * controller =[[EKEventEditViewController alloc] init];
controller.eventStore = eventStore;
controller.editViewDelegate = self;
[self presentModalViewController: controller animated:YES]'



}

-(void) eventEditViewController:(EKEventEditViewController *) controller didCompleteWithAction:(EKEventEditViewAction)action{
[self dismissModalViewControllerAnimated:YES];
}

1 个答案:

答案 0 :(得分:0)

您需要将事件分配给EKEventEditViewController。您将详细信息填入事件对象。

EKEventStore *store = [[EKEventStore alloc] init];
EKEvent *event = [store eventWithIdentifier:@"some identifier"];
if(!event)
{
    event = [EKEvent eventWithEventStore:store];
    event.startDate = someDate;
    event.endDate = someEndDate;
    event.location = someLocationString;
    event.availability = EKEventAvailabilityBusy;
    event.title = @"Title here";
}
EKEventEditViewController *ekVC = [[EKEventEditViewController alloc] init];
ekVC.event = event;
ekVC.editViewDelegate = self;
[self presentModalViewController:ekVC animated:YES];