I have a table view it displays data which we select time using the date picker in an action sheet.
in this table view each row having a custom cell ‘ReminderCell’ with a label and an uiswitch button
1.Custom cell
![enter image description here][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];
}
When user selects a row an action sheet with a date picker popups
![enter image description here][3]
- (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];
}
Now i need set reminder by select date from this date picker and set on when switch on.
Thanks in advance
UIKit offers the NSLocalNotification object that is a more high-level abstraction for your task.
in appDelegate.m
To reshudle the alarm
repeatInterval
The calendar interval at which to reschedule the notification.
@property(nonatomic) NSCalendarUnit repeatInterval
Discussion
If you assign an calendar unit such as weekly (NSWeekCalendarUnit) or yearly (NSYearCalendarUnit), the system reschedules the notification for delivery at the specified interval. The default value is 0, which means don’t repeat.
repeatCalendar
The calendar the system should refer to when it reschedules a repeating notification.
@property(nonatomic, copy) NSCalendar *repeatCalendar
Discussion
The default value is nil, which indicates that the current user calendar is used. (The current user calendar is returned by the currentCalendar class method of NSCalendar.)
and to schedule a alarm
References
UILocalNotification Reference
UILocalNotification Tutorial
UILocalNotification Programming Guide
UILocalNotification cancel LocalNotification