目标C:UIDatePicker UIControlEventValueChanged仅在第二次选择时触发 [英] Objective C: UIDatePicker UIControlEventValueChanged only fired on second selection

查看:340
本文介绍了目标C:UIDatePicker UIControlEventValueChanged仅在第二次选择时触发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首次使用UIDatePickers。首先,我只是尝试使用从datePicker中选择的任何值更新文本字段(在倒计时模式下设置)。

Working with UIDatePickers for the first time. To start, I'm just trying to update a text field with whatever value is selected from the datePicker (set in count down mode).

它可以工作,但只有第二次用户选择时间。我的动作,durationSelected()仅被第二次调用,因此更新textField没有问题。

It works, but only the second time that a user selects a time. My action, durationSelected() is only called the second time, so there are no problems updating the textField.

以下是我在故事板中配置日期选择器的方法:

Here's how I configured the date picker in my storyboard:

以下是价值变更触发的操作:

Here's the action triggered on Value Changed:

来自DetailViewController.m

from DetailViewController.m

- (IBAction)durationSelected:(UIDatePicker *)sender
{
    self.durationTextField.text = [NSString stringWithFormat:@"%f seconds", sender.countDownDuration];
}

我尝试设置默认值,但没有效果。

I've tried setting a default value, which had no effect.

关于发生了什么的任何想法?

Any ideas about what's going on?

谢谢!

推荐答案

这似乎是UIDatePicker的iOS 7实现中的一个错误。我建议在上面备一个雷达。

This seems to be a bug in the iOS 7 implementation of UIDatePicker. I'd suggest filing a radar on it.

在iOS 6 SDK上构建并在iOS 6设备上运行会起作用,而在iOS 7设备上运行则不行。

Building on the iOS 6 SDK and running on an iOS 6 device will work, while running on an iOS 7 device will not.

您可以通过将此行代码添加到 - (void)viewDidLoad 方法

You can fix it by adding this line of code to your - (void)viewDidLoad method

[self.datePicker setDate:[NSDate date] animated:YES];

这篇关于目标C:UIDatePicker UIControlEventValueChanged仅在第二次选择时触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆