EventKit提醒

时间:2013-01-03 14:48:58

标签: eventkit reminders

我正在努力学习EventKit提醒的基础知识。我想在这里重新创建教程:http://www.techotopia.com/index.php/Using_iOS_6_Event_Kit_to_Create_Date_and_Location_Based_Reminders

但是当我尝试构建项目时,我的.m文件中出现“缺少方法声明的上下文”的错误 无论是在IBAction还是在CreateReminder。我试着在这里寻求建议,但似乎无法弄清楚我做错了什么。如果他们一直在遗漏一些阻止它构建的基本信息,那么必须说明这些教程的用途。如果有人可以提供帮助,我将非常感激。

#import <UIKit/UIKit.h>
#import <EventKit/EventKit.h>

@interface ReminderAppFirstViewController : UIViewController

@property (strong, nonatomic) EKEventStore *eventStore;

@property (strong, nonatomic) IBOutlet UIDatePicker *myDatePicker;
@property (strong, nonatomic) IBOutlet UITextField *reminderText;
- (IBAction)setReminder:(id)sender;
- (void)createReminder;
@end

- (IBAction)setReminder:(id)sender {

    if (_eventStore == nil)
    {
        _eventStore = [[EKEventStore alloc]init];
        [_eventStore requestAccessToEntityType:EKEntityTypeReminder comnpletion: ^(BOOL granted, NSError *error) ] {
            if (!granted)
                NSLog(@"Access to store not granted");
        }];

    }

    if (_eventStore != nil)
        [self createReminder];
}



- (void)createReminder
{
    EKReminder *reminder = [EKReminder
                            reminderWithEventStore:self.eventStore];

    reminder.title = _reminderText.text;

    reminder.calendar = [_eventStore defaultCalendarForNewReminders];

    NSDate *date = [_myDatePicker date];

    EKAlarm *alarm = [EKAlarm alarmWithAbsoluteDate:date];

    [reminder addAlarm:alarm];

    NSError *error = nil;

    [_eventStore saveReminder:reminder commit:YES error:&error];

    if (error)
        NSLog(@"error = %@", error);

        }

1 个答案:

答案 0 :(得分:0)

下面的部分看起来应该在.h文件中,而不是.m文件中。在.m的@interface部分中声明的属性基本上是私有的,只能在.m中访问。这些方法也不合适。也许是教程中的一个错误。

#import <UIKit/UIKit.h>
#import <EventKit/EventKit.h>

@interface ReminderAppFirstViewController : UIViewController

@property (strong, nonatomic) EKEventStore *eventStore;

@property (strong, nonatomic) IBOutlet UIDatePicker *myDatePicker;
@property (strong, nonatomic) IBOutlet UITextField *reminderText;
- (IBAction)setReminder:(id)sender;
- (void)createReminder;
@end