【问题标题】:How to add an event within a calendar如何在日历中添加事件
【发布时间】:2012-01-02 05:16:59
【问题描述】:

我正在为 iPad 做一个日历,直到现在 我有日历视图,但是,现在我需要在其中创建一个事件。 我在这个例子中使用 YFCalendar http://www.yellowfield.co.uk/blog/?p=28

现在我需要添加一个可以在当天时间添加的新事件

但是,我希望在类似于默认日历的小窗口中查看事件摘要。

Example_Image: http://media.wiley.com/Lux/45/271245.image1.jpg

我不知道我需要什么样的控制才能达到这个结果。

我不使用默认日历

一些建议? 最好有开源的东西来分析,无论如何,欢迎任何答案

【问题讨论】:

    标签: objective-c cocoa-touch ipad ios5 xcode4.2


    【解决方案1】:

    请参阅此处的活动套件编程指南:

    http://developer.apple.com/library/ios/#documentation/DataManagement/Conceptual/EventKitProgGuide/Introduction/Introduction.html

    这里是苹果示例代码:https://developer.apple.com/library/ios/samplecode/SimpleEKDemo/Introduction/Intro.html

    添加事件的代码使用 EKEventEditViewController:

    // Create an instance of EKEventEditViewController 
    EKEventEditViewController *addController = [[EKEventEditViewController alloc] init];
    
    // Set addController's event store to the current event store
    addController.eventStore = self.eventStore;
    addController.editViewDelegate = self;
    [self presentViewController:addController animated:YES completion:nil];
    

    添加后,您可以使用该教程中的代码获取事件,该代码使用谓词(在本例中为日期)检索事件:

    NSDate *startDate = [NSDate date];
    
    //Create the end date components
    NSDateComponents *tomorrowDateComponents = [[NSDateComponents alloc] init];
    tomorrowDateComponents.day = 1;
    
    NSDate *endDate = [[NSCalendar currentCalendar] dateByAddingComponents:tomorrowDateComponents
                                                                    toDate:startDate
                                                                   options:0];
    // We will only search the default calendar for our events
    NSArray *calendarArray = [NSArray arrayWithObject:self.defaultCalendar];
    
    // Create the predicate
    NSPredicate *predicate = [self.eventStore predicateForEventsWithStartDate:startDate
                                                                      endDate:endDate
                                                                    calendars:calendarArray];
    
    // Fetch all events that match the predicate
    NSMutableArray *events = [NSMutableArray arrayWithArray:[self.eventStore eventsMatchingPredicate:predicate]];
    
    return events;
    

    【讨论】:

    • 让我检查一下,它可以很好地用于我的个人日历,它将使用 JSON 接收和发送数据到 Web 平台?我不使用本地日历谢谢
    • 我看了视频,它很有用,但我不使用默认日历,所以,我不知道是否需要其他类型的东西,因为我正在使用 JSON 在网络平台中添加事件
    • 您能否澄清您的问题 - 您是否在手机应用程序中使用网络视图?您是否将 json 数据发送到服务器,然后维护服务器 clendar - 有点困惑...
    • 当然!我必须制作一个个人日历(它不是默认日历),我在其中使用 JSON 从 Web 平台接收和发送日期。因此,当我将事件添加到我的个人日历(由我创建)时,在日历的单元格内添加一个事件。所以,我需要知道如何创建事件的详细视图,例如这张图片media.wiley.com/Lux/45/271245.image1.jpg,并可以编辑事件。这个我来宾的详细事件显示在一个弹出控件中。我只是想知道如何创建这个视图 --> r-force.up.seesaa.net/image/e_101103_0.png 谢谢!
    猜你喜欢
    • 1970-01-01
    • 2011-04-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-05-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多