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

查看:35
本文介绍了Objective-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.

这是怎么回事?

推荐答案

这似乎是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];

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

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