Andrew
Andrew

Reputation: 16051

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”.

Upvotes: 7

Views: 9263

Answers (1)

maxbareis
maxbareis

Reputation: 886

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]];

Upvotes: 6

Related Questions