我正在制作一个iPhone应用程序,我在其中使用日期时间选择器并在文本字段中显示所选日期.现在我想更新文本字段,因为日期选择器中的选定日期发生了变化.
我怎样才能做到这一点.给我一些解决方案.
提前致谢.
UIDatePicker只需为控件事件添加目标和操作即可通知您更改UIControlEventValueChanged.有关更多详细信息,请查看UIDatePicker参考.
一个简单的实现看起来像这样:
[picker addTarget:self
action:@selector(datePickerValueChanged:)
forControlEvents:UIControlEventValueChanged];
Run Code Online (Sandbox Code Playgroud)
然后...
- (void)datePickerValueChanged:(id)sender{
UIDatePicker *picker = (UIDatePicker *)sender;
NSString *dateString;
dateString = [NSDateFormatter localizedStringFromDate:[picker date]
dateStyle:NSDateFormatterMediumStyle
timeStyle:NSDateFormatterNoStyle];
[textField setText:dateString];
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4637 次 |
| 最近记录: |