Ios UIDatePicker:有日期和时间选项,但如何在应用程序中同时显示这两个选项?
编辑:以备将来参考:为NSDateFormatter找到此文件。本文档显示了不同的代码,以显示您正在寻找的正确日期和时间格式。干杯 我正在创建一个应用程序,它使用UIDatePicker来选择事件的日期和时间(故事板中有一个选项) 我想知道如何在选择/保存后在标签中显示日期和时间。现在,这就是我在整个应用程序中的部分代码。我的问题是:我是否更改格式化程序代码以允许UIDatePicker在我的应用程序中显示日期和时间?有办法做到这一点吗?提前谢谢 主视图控制器Ios UIDatePicker:有日期和时间选项,但如何在应用程序中同时显示这两个选项?,ios,iphone,uidatepicker,Ios,Iphone,Uidatepicker,编辑:以备将来参考:为NSDateFormatter找到此文件。本文档显示了不同的代码,以显示您正在寻找的正确日期和时间格式。干杯 我正在创建一个应用程序,它使用UIDatePicker来选择事件的日期和时间(故事板中有一个选项) 我想知道如何在选择/保存后在标签中显示日期和时间。现在,这就是我在整个应用程序中的部分代码。我的问题是:我是否更改格式化程序代码以允许UIDatePicker在我的应用程序中显示日期和时间?有办法做到这一点吗?提前谢谢 主视图控制器 -(void)confi
-(void)configureCell:(MasterEventCell *)cell atIndexPath:(NSIndexPath *)indexPath{
static NSDateFormatter *formatter = nil;
if (formatter == nil) {
formatter = [[NSDateFormatter alloc] init];
[formatter setDateStyle:NSDateFormatterMediumStyle];
}
Event *eventAtIndex = [_fetchedResultsController objectAtIndexPath:indexPath];
cell.eventDetailsLabel.text = eventAtIndex.detail;
cell.eventLocationLabel.text = eventAtIndex.location;
cell.eventDateTimeLabel.text = [formatter stringFromDate:(NSDate *)eventAtIndex.date];
}
- (void)configureView
{
Event *theEvent = self.event;
static NSDateFormatter *formatter = nil;
if (formatter == nil) {
formatter = [[NSDateFormatter alloc] init];
[formatter setDateStyle:NSDateFormatterMediumStyle];
}
if (theEvent) {
self.detailLabel.text = theEvent.detail;
self.locationLabel.text = theEvent.location;
self.dateTimeLabel.text = [formatter stringFromDate:(NSDate *)theEvent.date];
}
}
详细视图控制器
-(void)configureCell:(MasterEventCell *)cell atIndexPath:(NSIndexPath *)indexPath{
static NSDateFormatter *formatter = nil;
if (formatter == nil) {
formatter = [[NSDateFormatter alloc] init];
[formatter setDateStyle:NSDateFormatterMediumStyle];
}
Event *eventAtIndex = [_fetchedResultsController objectAtIndexPath:indexPath];
cell.eventDetailsLabel.text = eventAtIndex.detail;
cell.eventLocationLabel.text = eventAtIndex.location;
cell.eventDateTimeLabel.text = [formatter stringFromDate:(NSDate *)eventAtIndex.date];
}
- (void)configureView
{
Event *theEvent = self.event;
static NSDateFormatter *formatter = nil;
if (formatter == nil) {
formatter = [[NSDateFormatter alloc] init];
[formatter setDateStyle:NSDateFormatterMediumStyle];
}
if (theEvent) {
self.detailLabel.text = theEvent.detail;
self.locationLabel.text = theEvent.location;
self.dateTimeLabel.text = [formatter stringFromDate:(NSDate *)theEvent.date];
}
}
在日期格式化程序上也调用
setTimeStyle:
把日期和时间写在标签上?如果您只想显示,则不需要选择器,NSDateFormatter将按照您想要的方式格式化日期和时间。我让用户选择日期和时间,然后在表视图单元格中显示他们的选择(以及他们选择的一些其他信息)。我只是想知道如何操作格式化程序代码以允许同时显示日期和时间,目前为止,我只看到用户输入信息后显示的日期。请使用格式化程序集同时显示日期和时间。(这意味着,除其他外,实际上要阅读NSDateFormatter的文档。)已经浏览了该文档,其中一些文档对于日期和时间的特定格式有点含糊不清。知道我需要什么了,谢谢!令人惊叹的!我知道必须要加上那样的东西。谢谢