Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do i set UIDatePicker's date to another date?

I have tried various things, including:

[timepicker setDate: [NSDate mondayalarmtime]];

and

timepicker.date = mondayalarmtime;

Each time, this line crashes the simulator. My mondayalarmtime is defined in viewDidLoad here:

 NSDateFormatter *inputFormat = [[NSDateFormatter alloc] init];
 [inputFormat setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
 NSDate *inputDate = [inputFormat dateFromString: @"2011-01-01 09:00:00"];

 NSLog (@"The input date %@", inputDate);

 NSDate *mondayalarmtime = inputDate;

The NSLog returns:

The input date 2011-01-01 09:00:00 +0000

Putting an NSLog asking for mondayalarmtime just before it tries to set thet imepicker to mondayalarmtime returns the same..

Mondays alarm time.. 2011-01-01 09:00:35 +0000

And then when it tries to set the timepicker date to mondayalarmtime, it crashes with the report:

Program received signal:  “EXC_BAD_ACCESS”.
like image 743
Andrew Avatar asked Jan 03 '11 15:01

Andrew


1 Answers

You are sending the mondayalarmtime message to NSDate. NSDate does not understand this message

Try setting a property with mondayalarmtime and calling the getter

[timepicker setDate:[self mondayalarmtime]];
like image 190
maxbareis Avatar answered Dec 05 '22 19:12

maxbareis