Prevent UIDatePicker from defaulting to current year - iphone

I have got a UIDatePicker to pick up Date of Birth. If someone doesn't select a year it defaults to current year. How can I prevent datepicker from defaulting to the current year? Please help.
Thanks
Sonia

It has to default to some year. You could set a maximum date though (like 1 year ago), and then set the date of the UIDatePicker to an invalid date (like today). Then just don't let the user continue if they haven't changed the year to a valid year.

According to The UIDatePicker Class Reference You can simply change the Date Property's value and thus changing the default value - wich is the control's creation date

Regarding your comment about a message - have you tried something like
UIAlertView *alert=[[UIAlertView alloc]initWithTitle:#"Warning" message:#"Please Enter correct birthday year" delegate:self cancelButtonTitle:#"ok" otherButtonTitles:nil];
Alert views are pop-up views that appear over the current view on the iPhone.
You may find iPhone Development 101 - UIAlertView informative

Before showing the date picker, you could call upon the
- (void)setDate:(NSDate *)date animated:(BOOL)animated;
method with the required date and the UIDatePicker will display that date when it comes on screen.

Related

Display Only Hours In UIDatePicker

I have the following code that sets up a UIDatePicker to show only time. I have two of these UIDatePickers displaying and I want to use them to allow the user to select a time range e.g. between 7 am and 5 pm.
UIDatePicker *datePicker=[[UIDatePicker alloc]init];
datePicker.frame=CGRectMake(-20, 0, 180, 200);
datePicker.datePickerMode = UIDatePickerModeTime;
[datePicker setMinuteInterval:0];
[datePicker setTag:1];
How can I set up the UIDatePicker so that it only shows hours and no minutes?
UIDatePicker isn’t that customizable. You’ll need to set up your own UIPickerView containing the time range you’re looking for. To fit the user’s date/time settings, you should use NSDateComponents and NSDateFormatter to get names for the hours that you need.
This does not take localization into account and will be wrong in practically any other language.
The best advice would be to file a radar at Apple requesting more customization of this API.

How to set UINotification for specific days like every Monday and Friday?

I am writing an alarm app. In the app, user can select days from the picker for setting alarm on that day with time. But I don't know to set alarm (UILocalNotification) for specific day in a week (0 - 7).
I just wanted to set fire date of UILocalNotification on specific day like ex. Monday, Friday and Sunday..
I have searched on net and got many similar forums but none of them worked for me.
Any suggestions ?
Set the local notification fireDate for the first notification that should be made. Then set the repeatInterval for the duration between any notification and the next notification.
It would be more helpful if you have included codes which you have tried.
Anyways,
NSDate myOwnDate; // myOwnDate can be a date that is on a specific day. Make sure it is a valid date variable
UILocalNotification* local_notification = [[UILocalNotification alloc] init];
[local_notification setFireDate:myOwnDate];
[local_notification setRepeatInterval:NSWeekCalendarUnit];
[local_notification setAlertBody: #"Your alarm is ringing!"];
UIApplication* app = [UIApplication sharedApplication];
[app scheduleLocalNotification:local_notification];
Pretty straightforward I would say.

Show Specific dates in Tapku library Calender

I have implemented Tapku Library calender in my olympic based iphone app. I want to enable a set of dates(Olympic dates) on it, so that user can only select those dates.
Don't know how to implement it in my app.
You need to use following delegate method for get selected date
- (void)calendarMonthView:(TKCalendarMonthView *)monthView didSelectDate:(NSDate *)d
{
NSLog(#"calendarMonthView didSelectDate");
}

Xcode - Showing month names in portuguese when using UIDatePicker

I am using the UIDatePicker and I'd like to show month names in Brazilian Portuguese. I've already tried to use the timeZone property, no success though.
Here is my code:
UIDatePicker *pv = [[UIDatePicker alloc] initWithFrame:CGRectMake(0,0,320,216)];
pv.datePickerMode = UIDatePickerModeDate;
pv.timeZone = [NSTimeZone timeZoneWithName:#"America/Sao_Paulo"];
Does anybody would help me?
Set the locale property on the picker to the locale you want, like this:
pv.locale = [[[NSLocale alloc] initWithLocaleIdentifier:#"pt_BR"] autorelease];
It should configure itself correctly. You may need to check [NSLocale availableLocaleIdentifiers] to determine if the locale you want is available/installed.
Clarification needed. Do you only want to set the date picker to Portuguese, and keep the rest of the app in the user's default language?
Normally the datepicker changes language with the user following the settings under settings/general/international. The datepicker will automatically adjust to the user's desired language, so you don't have to localize it directly.
You don't have to do anything. As soon as the iPhone is set to the proper locale, the UIDatePicker will show the proper values for you. That's why locale related methods and properties are deprecated. It relies on system configuration.

iphone application linking calendar with textfield

In my application i want to textField where user can put date. Now for taking date i need calendar so that user select date from it and it automatically fill into textField.
What would be the best approach to do so.
Thanks
UIDatePicker will allow the user to easily select the date.
uidatepicker and take the value changed
I built a fancy UITextField class that set up a UIDatePicker as its inputView. The main value to this is that, when the user taps into the text field, the date picker is brought up where the keyboard would normally be.
UIDatePicker *input = [[UIDatePicker alloc] init];
[input addTarget:self action:#selector(update:) forControlEvents:UIControlEventValueChanged];
(UITextField *)myTextField.inputView = input;
[input release];
Then, in the -[update:] method, use an NSDateFormatter to set the text in the textfield.