【发布时间】:2013-08-13 14:58:56
【问题描述】:
我是 iOS 新手,并不熟悉它的所有 API。我发现了如何在文本字段中显示选定的日期,但我不知道要写什么来显示与特定日期相关的特定(选定)文本。
这是我用来显示日期的代码。您知道我需要更改哪些内容才能在特定日期编写自己的文本吗?:
#import "ViewController.h"
@implementation ViewController
@synthesize datePicker;
@synthesize dateLabel;
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
#pragma mark - View lifecycle
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)viewDidUnload
{
[self setDateLabel:nil];
[self setDatePicker:nil];
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
}
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
}
- (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
}
- (void)viewDidDisappear:(BOOL)animated
{
[super viewDidDisappear:animated];
}
- (BOOL)shouldAutorotateToInterfaceOrientation (UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}
- (IBAction)touchButton:(id)sender {
NSDate *dateSelect = [datePicker date];
NSString *dateStamp = [[NSString alloc]initWithFormat:@"The date is %@", dateSelect];
dateLabel.text = dateStamp;
}
@end
(我有一个按钮、日期选择器和一个文本字段)
非常感谢您的回答。
【问题讨论】:
-
你绑定并设置了日期选择器的代理?
-
您的问题真的是关于如何格式化日期值的输出吗?
-
不,如果我的问题不清楚,我很抱歉。我希望一年中的每一天都有一个文本,例如每日报价。
标签: ios datepicker