UI target/action设计模式
来源:互联网 发布:宜昌网络买花花店 编辑:程序博客网 时间:2024/06/04 18:12
target/action设计模式
MyView.h
@interface MyView : UIView{ //保存对象 id _target; //保存方法 SEL _action;}//给实例变量_target,_action赋值- (void)addTarget:(id)target action:(SEL)action;<p style="margin-top: 0px; margin-bottom: 0px; font-size: 18px; font-family: Menlo;"><pre name="code" class="objc">@property(nonatomic,retain) UIView *greenView;@end
MyView.m
<pre name="code" class="objc">@implementation MyView- (void)dealloc{ [_greenView release]; [super dealloc];}- (id)initWithFrame:(CGRect)frame{ self = [super initWithFrame:frame]; if (self) { UIView *greenView=[[UIView alloc]initWithFrame:CGRectMake(40, 120, 100, 100)]; greenView.backgroundColor=[UIColor greenColor]; [self addSubview:greenView]; [greenView release]; self.greenView=greenView; } return self;}//给实例变量_target,_action赋值- (void)addTarget:(id)target action:(SEL)action{ _target=target; _action=action;}-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{ //让_target对象执行_action方法,参数是nil [_target performSelector:_action withObject:self.greenView];}@end
RootViewController.m
@implementation RootViewController-(void)loadView{ //在loadView中给self.view赋值,没有赋值之前self.view是空的。如果不重写loadView方法,则默认创建一个空白的view MyView *myView=[[MyView alloc]initWithFrame:CGRectMake(0, 0, 320, 480)]; myView.backgroundColor=[UIColor cyanColor]; [myView addTarget:self action:@selector(changeColor:)]; self.view=myView; [myView release];}- (void)changeColor:(UIView*)aView{ //改变颜色 float red=arc4random()%256/255.0; float green=arc4random()%256/255.0; float blue=arc4random()%256/255.0; UIColor *randColor=[UIColor colorWithRed:red green:green blue:blue alpha:1]; aView.backgroundColor=randColor;}@end
0 0
- UI target/action设计模式
- UI - Target-Action设计模式
- UI 04 target...action 设计模式
- UI阶段的 Target/Action设计模式
- UI-Target-action模式
- Target-Action 设计模式
- target/action设计模式
- Target-Action 设计模式
- target/action设计模式
- target/action 设计模式
- target - action 设计模式
- Target/Action 设计模式
- UIday05_zy01:target/action 设计模式
- 13.target/action设计模式
- UI开发----target/action设计模式和代理设计模式以及手势识别器
- target - action设计模式的思想
- iOS设计模式之Target-Action
- iOS开发 -- 耦合 ,target/action设计模式
- Google Code Jam 2015 Qualification Round: Problem D. Ominous Omino 【Small Input】
- Android Studio 入门指南
- No submodule mapping found in .gitmodules for path 'modules/PushMsgCenter'
- The full-stack employee(FSD)
- Activity的4种加载模式及Intent标识
- UI target/action设计模式
- POJ 2253 Frogger Kruskal最小生成树求解
- Python中列表转换成字典
- 二叉树Java实现
- 黑马程序员-----[20150416][Java内部类总结]
- linux exec与重定向
- 【万里征程——Windows App开发】如何保存、读取、删除应用数据
- 补发数据库第一章作业
- 004-struts2类型转换一