检测UIDatePicker是否正在滚动? [英] Detect if UIDatePicker is rolling?

查看:95
本文介绍了检测UIDatePicker是否正在滚动?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在模式视图中使用UIDatePicker选择日期.我发现,如果在日期选择器仍在滚动时关闭视图,则会得到EXC_BAD_ACCESS.

I'm using a UIDatePicker in a modal view, to select a date. I found that if the view is closed while the date picker is still rolling, I got a EXC_BAD_ACCESS.

当用户按一下按钮时,如何检测日期选择器正在滚动?

How can I detect of the date picker is rolling when the user tab a button?

我有两个想法:

1)检测值是否已更改:

1) detect if the value has changed with this:

[myDatePicker addTarget:self action:@selector(valueChanged:) forControlEvents:UIControlEventValueChanged];

但是我需要能够检测该值是否会改变.

But I would need to be able to detect if the value WILL change.

2)检查日期是否有效,但是在滚动日期选择器时,将返回前一个日期,当然是有效的.

2) check if the date is valid, but when the date picker is rolling, the previous date is returned, and of course is valid.

有什么想法吗?

推荐答案

为避免此崩溃,您无需尝试预测选择器何时将尝试向您的类发送操作方法调用,您只需在ViewController的dealloc例程中删除选择器的事件操作即可.

In order to avoid this crash, you don't need to try to predict when the picker will try to send an action method call to your class, instead, you simply remove the picker's event action in your ViewController's dealloc routine.

哎呀,正如评论中指出的那样,UIDatePicker没有委托.但是您可以为其分配动作事件.因此,相反,应删除指向要取消分配的对象的所有操作集.

oops, as was pointed out in a comment, the UIDatePicker doesn't have a delegate. But you can assign it action events. So instead, any actions set pointing to the object that is being dealloc'd should be removed.

- (void dealloc
{
    [myPicker removeTarget:self action:... forControlEvents:...];
    [myPicker release];
    [super dealloc];
}

这篇关于检测UIDatePicker是否正在滚动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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