0

작업 표의 날짜 선택 도구를 사용하여 시간을 선택하는 데이터를 표시하는 테이블보기가 있습니다. 이 테이블 뷰 UIswitch를 사용하여 작업 표에서 미리보기를 설정하십시오.

레이블 맞춤 셀 'ReminderCell'및 uiswitch 버튼을 갖는 각 행

1.Custom 셀 ! [여기서 화상 정보 입력] [1]

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 
    // Note: I set the cell's Identifier property in Interface Builder to DemoTableViewCell. 
    ReminderCell *cell = (ReminderCell *)[tableView dequeueReusableCellWithIdentifier:CellClassName]; 
    if (!cell) 
    { 
     NSArray *topLevelItems = [cellLoader instantiateWithOwner:self options:nil]; 
     cell = [topLevelItems objectAtIndex:0]; 
    } 

    //set from action sheet only this row 0 
    if(indexPath.row == 0) 
    { 
     if(date == nil) 
     { 
      date = [NSDate date]; 
     } 
     NSDateFormatter *timeFormatter = [[NSDateFormatter alloc] init]; 
     [timeFormatter setDateFormat:@"hh:mm a"]; 
     cell.label.text = [timeFormatter stringFromDate:date]; 
    } 
사용자가 날짜 선택 팝업

와 액션 시트를 행을 선택

! [여기서 화상 정보 입력] [3]

,451,515,
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 

    if(date == nil) 
    { 
     date = [NSDate date]; 
    } 
    NSDateFormatter *timeFormatter = [[NSDateFormatter alloc] init]; 
    [timeFormatter setDateFormat:@"hh:mm a"]; 

    //Add Action sheet 
    UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:nil 
                delegate:self 
              cancelButtonTitle:@"Cancel" 
             destructiveButtonTitle:nil 
              otherButtonTitles:@"Done",nil]; 

    // Add date picker to the action sheet 
    datePicker = [[UIDatePicker alloc] init]; 
    datePicker.datePickerMode = UIDatePickerModeTime; 
    [actionSheet addSubview:datePicker]; 
    [actionSheet showInView:self.navigationController.tabBarController.view];   
    [actionSheet setBounds:CGRectMake(0,0,320, 550)]; 
    [datePicker setFrame:CGRectMake(0, 138, 320, 216)]; 
    [datePicker release]; 
    [actionSheet release]; 
} 

이제 내가이 날짜 선택에서 선택 날짜별로 알림을 설정하고에 때 스위치를 설정할 필요가 없다. 미리 감사드립니다.

답변

1

UIKit은 작업에 대한 더 높은 수준의 추상화 객체 인 NSLocalNotification 객체를 제공합니다.

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {  

    UILocalNotification *aNotification = [launchOptions objectForKey: UIApplicationLaunchOptionsLocalNotificationKey]; 

    if (aNotification) { 
     //if we're here, than we have a local notification. Add the code to display it to the user 
    } 

    [self.window makeKeyAndVisible]; 
    return YES; 

} 

    - (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification { 

      //if we're here, than we have a local notification. Add the code to display it to the user 


    } 

appDelegate.m

UILocalNotification *yourNotification = [[UILocalNotification alloc] init]; 
    yourNotification.fireDate = [NSDate date]; // time at which the remainder has to be triggered 
    yourNotification.timeZone = [NSTimeZone defaultTimeZone]; 

    yourNotification.alertBody = @"Notification triggered"; 
    yourNotification.alertAction = @"Details"; 


/* if you wish to pass additional parameters and arguments, you can fill an info dictionary and set it as userInfo property */ 
    //NSDictionary *infoDict = //fill it with a reference to an istance of NSDictionary; 
    //aNotification.userInfo = infoDict; 

알람을 통지를 재조정에서

로부터, repeatInterval

캘린더 간격 reshudle한다.

@property (세분화) NSCalendarUnit로부터, repeatInterval 같은 주간 (NSWeekCalendarUnit)와 같은 토론

당신이 일정 단위를 할당하는 경우

또는 연간 ( NSYearCalendarUnit)는, 시스템은 지정된 간격으로 배달 알림 스케줄을 변경한다. 기본값은 0입니다. 이는 반복하지 않음을 의미합니다.

repeatCalendar

시스템은 반복 통지를 재 스케줄링 할 때 참조해야 캘린더.

@property (비 원자, 복사) NSCalendar * repeatCalendar 토론

기본값은 현재 사용자 달력이 사용되는 것을 나타낸다 전무하다. 현재 사용자 달력은 NSCalendar의 currentCalendar 클래스 메서드에 의해 반환됩니다.)

과 알람을 예약 할 수

UISwitch *onoff = [[UISwitch alloc] initWithFrame: CGRectZero]; 
    [onoff addTarget: self action: @selector(switchAction:) forControlEvents:UIControlEventValueChanged]; 
    // Set the desired frame location of onoff here 
    [self.view addSubview: onoff]; 


- (IBAction)switchAction:(id)sender { 

UISwitch *theSwitch = (UISwitch *)sender; 
    UITableViewCell *cell = (UITableViewCell *)theSwitch.superview; 
    UITableView *tableView = (UITableView *)cell.superview; 
    NSIndexPath *indexPath = [tableView indexPathForCell:cell]; 
    // From which you can find the index value to get the particular time of the datePicker you set 
if (onoff.on){ 
    NSLog(@"On"); 
    //set the alarm at given time from DatePicker using UILocalNotification 
    } 
    else{ 
     NSLog(@"Off"); 
    // cancel the alarm Local Notification here 
    } 
} 

참조

UILocalNotification Reference

UILocalNotification Tutorial

UILocalNotification Programming Guide

UILocalNotification cancel LocalNotification