iOS_target-action的使用
来源:互联网 发布:max内功版数据库转换 编辑:程序博客网 时间:2024/05/21 23:45
Target-Action的说明
常用的UIButton有"addTarget:self action:@selector"的点击事件。
由于UIButton继承于UIControl, 所以UIControl下面的子类都有"addTarget:self action:@selector"的点击事件功能。
|-- UIButton
|-- UITextField
UIControl---|-- UISlider
|-- UISwitch
|-- UIDatePicker
|-- UIPageControl
|-- UISegmentedControl
Target-Action的作用就是其他类使用类似Button的点击事件。
使用的方法:
1、自定义一个类
2、在自定义的类中,加入两个属性:
@property (nonatomic, assign) id target;
@property (nonatomic, assign) SEL action;
3、自定义的类的.m文件中。编写touch方法(相当于Button addTarget语句中的"forControlEvents:UIControlEventTouchUpInside" 语句,所有一般在touchesEnded事件中编写代码
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
// 将target和Action关联起来
[self.target performSelector:self.action withObject:self];
}
4、在要调用自定义类的ViewController中,实例化自定义的类(以下面的例子为例),然后设置自定义类的两个属性。其中的touchV.action = @selector(touchClicked:),相当于Button addtarget中的"action:@selector(clicked:)" 语句功能。
touchV.target = self;
touchV.action = @selector(touchClicked:);
5. 在ViewController中定义touchClicked:事件。
- iOS_target-action的使用
- Action的使用
- s:action的使用
- action标签的使用
- Action Bar的使用
- Action接口的使用
- Struts2的Action使用
- 2.Action的使用
- 各种Action的使用场合
- 【转帖】JSP Action的使用
- android action-bar的使用
- <s:action>标签的使用
- s:action标签的使用
- Action中通配符的使用
- Fuc和Action的使用
- Action!Call拨打电话(Intent.ACTION.CALL的使用)
- Bug-struts2的action的通配符使用
- 该使用QTP的Action还是Function?
- 编写Win32病毒的几个关键
- 辽宁师大男生求爱被拒纵火 欲与大三女生同归于尽
- 我没有说谎(5min)
- 苏格兰独立派批卡梅伦背弃承诺 未下放更多权力
- Google无法访问的解决办法
- iOS_target-action的使用
- ios开发知识总结--百科
- 怎么格式化已分区SD卡
- Vs自定义控件设计第一例(直线控件的设计)
- XML学习第二篇
- adt-bundle更新eclipse,以及搭建android环境
- 金正恩露面引新躁动 朝鲜官员:日美媒体又丢脸啦
- 使用DOM,SAX解析XML文档
- C++ 学习笔记_0012_函数(泰勒展开式、三角函数表)