Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

donaghy

macrumors member
Original poster
Aug 6, 2009
49
0
Hi all, I've got a UIDatePicker in a separate View Controller and is re-used throughout my app. I want to switch the UIDatePickerMode depending on whether a date input or time input is required. How do i switch the UIDatePickerMode programmatically? I've tried the below but it does not appear to work, the picker maintains it's default mode:

Code:
picker.datePickerMode = UIDatePickerModeTime;
picker.datePickerMode = UIDatePickerModeDate;

EDIT:
I've narrowed it down a bit. When i first initialise the date picker it maintains its default mode. Only afterwards does it allow me to change:

Code:
if (dateTimePicker == nil) 
	{
		dateTimePicker = [[DateTimePicker alloc] initWithNibName:@"DateTimePicker" bundle:nil];
		dateTimePicker.delegate = self;
	}
	
	dateTimePicker.picker.datePickerMode = UIDatePickerModeTime;
	[dateTimePicker showPicker];

So the above will not change the mode when it does initialise the control but will do afterwards
 
Last edited by a moderator:
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.