Display the time in table view by selecting the time from picker - iphone

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 :)

Related

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.

How to invalidate my app after a certain amount of time in iPhone using provisioning profile

I want my iPhone app to be valid only for a particular time period. This has to be done by provisioning profile and not through the App Store. Please give me some suggestions.
Create a NSDate that represents the end time of your app preview. Then compare it to the current time and if the result is grater then you should exit the app. Although it is better to display a message to the user that the preview period expired as apple does not provide a straight forward way to exit the app.
NSString *dateString = #"25-Dec-10";
NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc] init] autorelease];
dateFormatter.dateFormat = #"dd-MMM-yy";
NSDate *endDate = [dateFormatter dateFromString:dateString];
if([[NSDate date] timeIntervalSinceDate:endDate] >= 0){
//Display message to the user
}

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.

how to display UIPickerview in dialog box

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

Invoke a date picker instead of a standard keyboard

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.