Target_Action
来源:互联网 发布:威廉叶芝知乎 编辑:程序博客网 时间:2024/05/22 09:05
#import "AppDelegate.h"
#import "MainViewController.h"
@interface AppDelegate ()
@end
@implementation AppDelegate
- (void)dealloc
{
[_windowrelease];
[superdealloc];
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window = [[UIWindowalloc] initWithFrame:[[UIScreenmainScreen] bounds]];
// Override point for customization after application launch.
self.window.backgroundColor = [UIColorwhiteColor];
[self.windowmakeKeyAndVisible];
[_windowrelease];
MainViewController *mainVC = [[MainViewControlleralloc] init];
self.window.rootViewController = mainVC;
[mainVCrelease];
return YES;
}
#import "MainViewController.h"
#import "TouchView.h"
@interface MainViewController ()
@end
@implementation MainViewController
- (void)viewDidLoad {
[superviewDidLoad];
// Do any additional setup after loading the view.
//自定义视图实现点击
TouchView *touchV = [[TouchViewalloc] initWithFrame:CGRectMake(20,20, 335, 335)];
touchV.backgroundColor = [UIColorredColor];
// touchV.alpha = 0;
[self.viewaddSubview:touchV];
[touchVrelease];
touchV.target =self;
touchV.action =@selector(touchAction:);
}
- (void)touchAction:(TouchView *)view
{
NSLog(@"touchView被点击了");
}
#import <UIKit/UIKit.h>
@interface TouchView :UIView
// 执行方法的对象
@property (nonatomic,assign)id target;
// target对象的一个方法
@property (nonatomic,assign)SEL action;
@end
#import "TouchView.h"
@implementation TouchView
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
NSLog(@"点击");
// CGFloat red = arc4random() % 256 / 255.0;
// CGFloat green = arc4random() % 256 / 255.0;
// CGFloat blue = arc4random() % 256 / 255.0;
// self.backgroundColor = [UIColor colorWithRed:red green:green blue:blue alpha:1.0];
// 让 target 调用 action 方法
// 就 target和action 具体是什么,TouchView本身不需要关心
[self.targetperformSelector:self.actionwithObject:nil];
}
@end
- target_action
- Target_Action
- Target_Action 设计模式
- 模拟target_action的内部实现
- greenDAO系列3--又是介绍
- 2016届 阿里巴巴校招研发工程师C/C++笔试题--2015.08.23
- PHP+memcached+Mysql(主从)
- U盘装win7/win8 32位&64位系统
- 2034 人见人爱A-B【二分+排序】
- Target_Action
- 文件操作(NSFileManager)
- 一些极其有用的Lua代码
- Linux学习笔记 - 版本选择与安装
- greenDAO系列4--构建模型
- 嵌入式相关方向
- greenDAO系列5--查询
- Enums in JavaScript
- 【算法结构】一些经典的算法和数据结构的问题