set datepicker at a specific time

Go To StackoverFlow.com

0

Hi guys i have a problem

i my code i set a datepicker with the date of today, after that if the user change the picker i set a alarm to ring at the date of picker.

How can i "block the picker" on these date?

here my code, i hope in your help

NSDate *pickerDate = [NSDate date];

NSCalendar *calendar = [NSCalendar autoupdatingCurrentCalendar];


// Divisione della data in fattori
NSDateComponents *dateComponents = [calendar components:( NSYearCalendarUnit | NSMonthCalendarUnit |  NSDayCalendarUnit )
                                               fromDate:pickerDate];
NSDateComponents *timeComponents = [calendar components:( NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit )
                                               fromDate:pickerDate];
// Set Up dell'alarme considerando tutti i fattori
NSDateComponents *dateComps = [[NSDateComponents alloc] init];
[dateComps setDay:[dateComponents day]];
[dateComps setMonth:[dateComponents month]];
[dateComps setYear:[dateComponents year]];
[dateComps setHour:[timeComponents hour]];
[dateComps setMinute:[timeComponents minute]];
//Notifica in meno di un minuto
[dateComps setSecond:0];
NSDate *itemDate = [calendar dateFromComponents:dateComps];
[dateComps release];
[alarmDatePickerUno setDate:itemDate animated:YES];
[alarmDatePickerDue setDate:itemDate animated:YES];

   }


 // ALARM UNO
 // Set Allarme Uno

 -(IBAction)setAlarmUno:(id)sender{

NSLog(@"picker in allarme");

NSCalendar *currentCalendar = [NSCalendar currentCalendar]; 

//Setting dell'allarme in base al picker
AlarmDateUno = [alarmDatePickerUno date];
NSLog(@"allarme settata alle");
NSLog(@"%@", AlarmDateUno);
2012-04-05 21:14
by Acunamatata


1

alarmDatePickerUno.userInteractionEnabled = NO;
alarmDatePickerDue.userInteractionEnabled = NO;

EDIT AFTER CLARIFICATION

If you want to use a date between app launches, you need to persist the date somehow. I would suggest using NSUserDefaults, but you could also go for the more complicated solution of Core Data. Using NSUserDefaults you would check every time you create your UIDatePicker for the saved value and use that to initialize the picker.

// Get the date
NSDate *unoDate = [[NSUserDefaults standardUserDefaults] objectForKey:@"PickerUnoKey"];
if (unoDate) { // If we have a persisted date, we set the date of the datePicker
    [alarmDatePickerUno setDate:unoDate animated:NO];
}

Then when the user changes the value of the picker, you need to store the new value.

// When the datePicker value has changed, we store the value
[[NSUserDefaults standardUserDefaults] setObject:alarmDatePickerUno.date forKey:@"PickerUnoKey"];
2012-04-05 21:21
by Paul Hunter
Thanks but that's not what i looking for, that block the user interaction, do not block the date picker on the alarm date - Acunamatata 2012-04-06 04:55
Maybe I need to understand what you mean by 'block'. Do you want to change the date of the datePicker, or do you want set an unchangeable date for the picker. I'm not sure I understand you - Paul Hunter 2012-04-06 09:50
ok, i try to explain with my poor english, i want that the date picker after set alarm on stay on the date of alarm and don't change until the user move it - Acunamatata 2012-04-06 10:02
And when does it change? Do you unload it or change its date in code? I'm not sure when the date would change without the user moving it - Paul Hunter 2012-04-06 10:13
when i close the app in the multistaking.. - Acunamatata 2012-04-06 10:56
see my edited answer - Paul Hunter 2012-04-06 11:13
In Italy we say "Non è chiaro, è cristallino" is something "it's not clear is crystalline". thanks very much, work and i understand why, thank you very much - Acunamatata 2012-04-06 12:57
Ads