2013-01-03 96 views
0

我拉我的頭髮試圖瞭解EventKit提醒的基礎知識。我試圖重新這裏的教程:http://www.techotopia.com/index.php/Using_iOS_6_Event_Kit_to_Create_Date_and_Location_Based_RemindersEventKit提醒

但是當我嘗試建立的項目,我在 無論是在IBAction爲「爲方法聲明中缺少上下文中的」我的.m文件,並在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); 

     } 

回答

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