I am new to iPhone.
I need to display UIPickerview in UIAlertView and I need to get UIPickerview selected value.
Can anyone please post some code or link?
I will not do it.
I am afraid it is not possible to 'pack' UIPickerView into UIAlertView. UIPickerView seems to be always AS wide AS the whole screen (at least on the iPhone) - so even if you manage to add the picker as a subview, it will cover the alert.
I think it will spoil Apple Human Interface Guidelines.
Why do you insist to present a picker in alert? Can't you present it alone, without alert?
I would strongly recommend not doing that. Use the picker view as it's intended—as it's used in Clock and Calendar, i.e. at the bottom of the screen—and you're much less likely to get your app rejected by Apple for violating their Human Interface Guidelines.
As for the alert, you could create something yourself that looks similar, but I don't see why you'd want to combine a alert and a datePicker.
To access the datePicker's date, you need to have it declared in your code. Then you can simply use this:
NSDate *date = self.datePicker.date;
To get the date from a datePicker named datePicker.
To get this date into a string, which you probably want, do this:
NSDateFormatter *formatter = [[[NSDateFormatter alloc] init] autorelease];
[formatter setDateFormat:#"dd MMM, yyyy"];
NSString *stringFromDate = [formatter stringFromDate:date];
Related
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.
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.
I am making an iphone app, in which I wanna to implement the time picker. The time which i select from time picker must be displayed in table view. So how should I connect the time picker and table view to get the output.
Please give me answer.
Thanks in advance.
You can do it like this...
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
dateFormatter.dateFormat = #"d MMM yyyy";
You can do it in the UITableview delegate like this.....
cell.textLabel.text=[dateFormatter stringFromDate:datePicker.date];
where datePicker is the UIDatePicker...
You can also have the dateFormatter as a global variable if u want.....
Hope this helps.
Happy coding :)
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.
I need to invoke a UIDatePicker when i tap on a textfield. Usually when we tap on a textfield the keyboard pops up. But I need a date picker instead of that. Can anyone help me please...!
Thank you in advance.
UIDatePicker returns NSDdate. Use NSDateFormatter to get the string you want:
NSDateFormatter *format = [[NSDateFormatter alloc] init];
[format setDateFormat:#"yyyy-MM-dd"];
NSLog(#"%#", [format stringFromDate:newDate]);
A textfield is a control you use for text input. This is why tapping on it the keyboard pops up. If you need a date picker, simply use directly a date picker if you have space in your view, otherwise use a button and set the target-action of the button so that it shows a new view containing your date picker.