Target_Action
2015-08-23 14:33
204 查看
#import "AppDelegate.h"
#import "MainViewController.h"
@interface
AppDelegate ()
@end
@implementation AppDelegate
- (void)dealloc
{
[_window
release];
[super
dealloc];
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary
*)launchOptions {
self.window = [[UIWindow
alloc] initWithFrame:[[UIScreen
mainScreen] bounds]];
// Override point for customization after application launch.
self.window.backgroundColor = [UIColor
whiteColor];
[self.window
makeKeyAndVisible];
[_window
release];
MainViewController *mainVC = [[MainViewController
alloc]
init];
self.window.rootViewController = mainVC;
[mainVC
release];
return
YES;
}
#import "MainViewController.h"
#import "TouchView.h"
@interface
MainViewController ()
@end
@implementation MainViewController
- (void)viewDidLoad {
[super
viewDidLoad];
// Do any additional setup after loading the view.
//
自定义视图实现点击
TouchView *touchV = [[TouchView
alloc] initWithFrame:CGRectMake(20,
20, 335,
335)];
touchV.backgroundColor = [UIColor
redColor];
// touchV.alpha = 0;
[self.view
addSubview:touchV];
[touchV
release];
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.target
performSelector:self.action
withObject:nil];
}
@end
#import "MainViewController.h"
@interface
AppDelegate ()
@end
@implementation AppDelegate
- (void)dealloc
{
[_window
release];
[super
dealloc];
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary
*)launchOptions {
self.window = [[UIWindow
alloc] initWithFrame:[[UIScreen
mainScreen] bounds]];
// Override point for customization after application launch.
self.window.backgroundColor = [UIColor
whiteColor];
[self.window
makeKeyAndVisible];
[_window
release];
MainViewController *mainVC = [[MainViewController
alloc]
init];
self.window.rootViewController = mainVC;
[mainVC
release];
return
YES;
}
#import "MainViewController.h"
#import "TouchView.h"
@interface
MainViewController ()
@end
@implementation MainViewController
- (void)viewDidLoad {
[super
viewDidLoad];
// Do any additional setup after loading the view.
//
自定义视图实现点击
TouchView *touchV = [[TouchView
alloc] initWithFrame:CGRectMake(20,
20, 335,
335)];
touchV.backgroundColor = [UIColor
redColor];
// touchV.alpha = 0;
[self.view
addSubview:touchV];
[touchV
release];
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.target
performSelector:self.action
withObject:nil];
}
@end
相关文章推荐
- linux ngingx一些操作
- greenDAO系列3--又是介绍
- POJ 1111 Image Perimeters(dfs)
- 利用BufferedInputStream bufferedOutputStream读写文件
- PHP+memcached+Mysql(主从)
- Java之旅hibernate(4)——hibernate入门示例
- setDefaultCloseOperation()参数得使用说明
- 编写高质量代码改善C#程序的157个建议——建议131:用PascalCasing命名公开元素
- 一个简单的反汇编引擎的实现小记
- greenDAO系列2--如何开始
- 冒泡函数
- 去哪网实习总结:JavaWeb中文传参乱码问题的解决(JavaWeb)
- Spring Object/XML mapping example
- [CQOI2013]二进制a+b
- hdu 5418 Victor and World 最短路 floyd 解题报告
- 浙江大学PAT考试1009~1012(1010上帝是冠军。。)
- 使用Java中间MessageDigest该文本MD5加密(Java中间MD5样品加密算法演示)
- 数据仓库原理<1>:数据库与数据仓库
- 搭建园区拓扑
- greenDAO系列1--概要