objective-c - 如何更改标签上的日期选择器选定值
<p><p>我想在标签上显示从 datepicker 中选择的日期,但标签只显示当前日期它不显示我从 datepicker 中选择的日期这是代码请告诉我如何更改文本标签从日期选择器中随机选择的日期</p>
<pre><code>#import "ViewController.h"
@implementation ViewController
@synthesize datepicker,mylabel;
- (void)didReceiveMemoryWarning
{
;
// Release any cached data, images, etc that aren't in use.
}
#pragma mark - View lifecycle
- (void)viewDidLoad
{
;
NSDate *chosen = datepicker.date;
NSDateFormatter *formatter = [init];
formatter.dateStyle = NSDateFormatterMediumStyle;
mylabel.text = ;
;
// Do any additional setup after loading the view, typically from a nib.
}
- (void)viewDidUnload
{
;
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (void)viewWillAppear:(BOOL)animated
{
;
}
- (void)viewDidAppear:(BOOL)animated
{
;
}
- (void)viewWillDisappear:(BOOL)animated
{
;
}
- (void)viewDidDisappear:(BOOL)animated
{
;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}
@end
</code></pre></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><pre><code> // code for Date picker for current date
datepicker=[initWithFrame:CGRectMake(0, 200, 320, 150)];
//;
datepicker.date = ;
datepicker.datePickerMode=UIDatePickerModeDate;
NSDateFormatter *df = [ init];
df.timeStyle = NSDateFormatterNoStyle;
label.text=[NSString stringWithFormat:@"%@",
]];
df.dateFormat = @"yyyy-MM-dd";
// set action for date picker
[datepicker addTarget:selfaction:@selector(DateChange:)
forControlEvents:UIControlEventValueChanged];
//method for change date
- (void)DateChange:(id)sender
{
NSDateFormatter *dateFormatter = [ init];
;
label.text = ;
date.text=strDate;
}
</code></pre></p>
<p style="font-size: 20px;">关于objective-c - 如何更改标签上的日期选择器选定值,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/13044724/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/13044724/
</a>
</p>
页:
[1]