如何清除控件的Target-Action
2015-01-30 13:31
288 查看
继承自UIControl的控件都可以通过-(void)addTarget:action:forControlEvents的消息进行某些事件处理函数的注册,在不需要的时候还可以通过-(void)removeTarget:action:forControlEvents取消事件处理函数。不过应用开发中在添加时会逐个添加,但在清理时通常则是希望一次性清理干净。但-(void)removeTarget:action:forControlEvents需要传入指定target,因此只能清理指定target的处理函数,而不能清理全部。为此需要对UIControl进行相应的扩张,代码如下:
//Category声明: @interface UIControl (Additions) - (void)removeAllTargets; @end //Category实现: @implementation UIControl (Additions) - (void)removeAllTargets { for (id target in [self allTargets]) { [self removeTarget:target action:NULL forControlEvents:UIControlEventAllEvents]; } } @end
相关文章推荐
- iPhone How-to:如何清除控件的Target-Action
- 如何清除控件的Target-Action
- 如何在客户端清除fileUpLoad控件的文件路径
- 如何在客户端清除fileUpLoad控件的文件路径
- 如何清除应用程序承载 WebBrowser 控件时缓存
- 关于WeX5的carousel控件如何清除图片和增加图片
- IOS中的target action控件的实现
- Flex中如何利用videoPlayer属性和mx_internal命名空间,清除VideoDisplay控件内容
- 在ASP.NET MVC中如何让ASCX用户控件具有Action / Controller
- iOS如何实现传值---target-action设计模式
- 关于如何在 Unity 的 UI 菜单中默认创建出的控件 Raycast Target 属性默认为 false
- 如何清除应用程序承载 WebBrowser 控件时缓存
- 如何自己定义RetargetAction
- iOS开发封装带有Button的UIView控件,使用target-action模式给button添加点击事件
- asp.net textbox 控件如何清除缓存
- 如何在客户端清除fileUpLoad控件的文件路径
- 如何清除或初始化 easyui 的 treegrid 控件的数据
- 如何定制日历控件显示的星期文字
- 如何在VC6或者VC7下用 ATL做一个OpenGL的(COM)控件?
- 如何利用一个FILE控件,一次上传多个附件到数据库