在日历中添加事件后,Textview将被取消分配

时间:2013-11-01 05:02:08

标签: ios iphone ios6.1

我的屏幕为:enter image description here

第一个文本字段会显示日期选择器 第二个带来一个选择器 第三个是默认的textview。

点击添加提醒按钮后,事件将添加到日历中,屏幕弹出并返回到原始屏幕。一旦我点击文本视图返回到同一屏幕,我收到此错误消息: - [ReminderViewController respondsToSelector:]:发送到解除分配的实例0x17dc7370的消息

添加事件并返回主屏幕的代码如下:

          #pragma mark - calendar Event methods
     - (IBAction)btn_reminder_click:(id)sender{

     [self addEventTocalendar:sender];
    }

    - (void)addEventTocalendar:(id)sender{
        EKEventStore *store = [[EKEventStore alloc] init];
        [store requestAccessToEntityType:EKEntityTypeEvent completion:^(BOOL granted, 
        NSError *error) {
    if (!granted) { return; }
    EKEvent *event = [EKEvent eventWithEventStore:store];
    event.title  = @"Pickup Reminder";


    event.startDate = self.selectedDate;
    event.endDate = [event.startDate dateByAddingTimeInterval:60*60];//set 1 hour meeting
    event.notes = txt_notes.text;
    event.recurrenceRules = EKRecurrenceFrequencyDaily;
    [event addAlarm:[EKAlarm alarmWithRelativeOffset:60.0f * -5.0f]];
    if (selectedIndex == 1) {
        [event addRecurrenceRule:[[EKRecurrenceRule 
        alloc]initRecurrenceWithFrequency:EKRecurrenceFrequencyDaily interval:1 end:Nil]];

    }
    else if (selectedIndex == 2){
        [event addRecurrenceRule:[[EKRecurrenceRule 
        alloc]initRecurrenceWithFrequency:EKRecurrenceFrequencyWeekly interval:1 
      end:Nil]];
    }
    else if (selectedIndex == 3){
        [event addRecurrenceRule:[[EKRecurrenceRule 
        alloc]initRecurrenceWithFrequency:EKRecurrenceFrequencyMonthly interval:1 
        end:Nil]];
    }
    else if (selectedIndex == 4){
        [event addRecurrenceRule:[[EKRecurrenceRule 
        alloc]initRecurrenceWithFrequency:EKRecurrenceFrequencyYearly interval:1 
       end:Nil]];
    }
    [event setCalendar:[store defaultCalendarForNewEvents]];
    NSError *err = nil;
    [store saveEvent:event span:EKSpanThisEvent commit:YES error:&err];
    NSString *savedEventId = event.eventIdentifier;  //this is so you can access this 
     event later
    BOOL isSuceess=[store saveEvent:event span:EKSpanThisEvent error:&err];
    NSLog(@"the print is %d",isSuceess);
    // This needs to be done as the UIKIT was getting called from the seconadary thread 
   and therefore to show the alert view in the main thread and to prevent the hanging of 
     the app I have to call the Aletview method in the main thread.
    // i.e dispatch the event in the main thread

    if(isSuceess){
        UIAlertView *alertview = [[UIAlertView alloc] initWithTitle:@"Event" 
    message:@"Event added in calendar" delegate:self cancelButtonTitle:@"OK" 
     otherButtonTitles:nil];
        dispatch_async(dispatch_get_main_queue(), ^{
            [alertview show];

        });
    }
    else {
        UIAlertView *alertview = [[UIAlertView alloc] initWithTitle:@"Event" message:[err
        description] delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
        dispatch_async(dispatch_get_main_queue(), ^{
            [alertview show];
        });
    }
}];
}
      - (void)back{
       [self.navigationController popViewControllerAnimated:YES];
       }     
        #pragma mark - UIAlertViewDelegate methods
      - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:
     (NSInteger)buttonIndex{
        [self.navigationController popViewControllerAnimated:YES];

}

请帮助我,因为我在过去的四天里遇到了这个问题而没有得到理由或解决方案。

0 个答案:

没有答案