Object-C Target-Action模式 回调
target - action设计模式 是一种比较常见的设计模式,比如我们在用button的时候,给button添加一个事件,我们就用到了target - action设计模式.现在我们就用target - action设计模式 做一个button,还原button的设计原理,当然了 我们还要加上tap手势.
human.h
//
// Human.h
// ZWLimitCounterDemo
//
// Created by nan on 2021/12/9.
// Copyright © 2021 wang_ziwu. All rights reserved.
//#ifndef Human_h
#define Human_h#import <Foundation/Foundation.h>@interface Human : NSObject
-(void)say:(id)target Action:(SEL)action;
@end#endif /* Human_h */
Human.m
//
// Human.m
// ZWLimitCounterDemo
//
// Created by nan on 2021/12/9.
// Copyright © 2021 wang_ziwu. All rights reserved.
//#import "Human.h"@implementation Human
-(void)say:(id)target Action:(SEL)action
{// IMP imp1 = [target methodForSelector:action];[target performSelector:action withObject:@"Human中的say方法"];NSLog(@"Human中的say方法");
}
@end
ViewController.h
//
// ViewController.h
// ZWLimitCounterDemo
//
//#import <UIKit/UIKit.h>@interface ViewController : UIViewController@end
ViewController.m
//
// ViewController.m
// ZWLimitCounterDemo
//
//
#import "ManagerMessage.h"
#import "ComponentBlock.h"
#import "ObjcObject.h"
#import "Human.h"
#import "WKLLogger.h"#import "ViewController.h"
#import "UITextView+ZWLimitCounter.h"
@interface ViewController ()
@property (weak, nonatomic) IBOutlet UITextView *firstTextView;
- (IBAction)imppress:(id)sender;@end@implementation ViewController {
}//回调函数
-(void)messageCallBack:(NSString *)string
{self.firstTextView.text=string;
}- (void)viewDidLoad {[super viewDidLoad];// Do any additional setup after loading the view, typically from a nib.[self configFirstTextView];[self configSecndTextView];self.firstTextView.text=@"测试";}
- (void)configFirstTextView{self.firstTextView.layer.borderWidth = 1;self.firstTextView.layer.borderColor = [UIColor lightGrayColor].CGColor;self.firstTextView.zw_limitCount = 10;
}
- (void)configSecndTextView{CGRect rect = CGRectMake(10, 200, [UIScreen mainScreen].bounds.size.width-20, 60);UITextView *secondTextView = [[UITextView alloc] initWithFrame:rect];secondTextView.layer.borderWidth = 1;secondTextView.layer.borderColor = [UIColor lightGrayColor].CGColor;secondTextView.zw_limitCount = 10;[self.view addSubview:secondTextView];
}
- (void)didReceiveMemoryWarning {[super didReceiveMemoryWarning];// Dispose of any resources that can be recreated.
}- (IBAction)imppress:(id)sender {//Class c =NSClassFromString(@"Human");//[[c new] say];Human *human =[Human new];[human say:self Action:@selector(messageCallBack:)];}@end
Object-C Target-Action模式 回调相关推荐
- 通过 Windows 用户模式回调实施的内核攻击
这篇文章翻译自一篇多年之前的论文,原文作者是 Tarjei Mandt.原文系统地描述了 win32k 的用户模式回调机制以及相关的原理和思想,可以作为学习 win32k 漏洞挖掘的典范.早前曾经研读 ...
- UI一揽子计划 5 (Target: Action: 、Protocol Delegate、 UIImageView 、手势识别器)
一.target/ action 设计模式 耦合是衡量⼀一个程序写的好坏的标准之一, 耦合是衡量模块与模块之间关联程度的指标 "高内聚,低耦合"是⾯面 ...
- STAR-Situation\Target\Action\Result
STAR STAR是SITUATION(背景).TASK(任务).ACTION(行动)和RESULT(结果)四个英文字母的首字母组合. 通常,应聘者求职材料上写的都是一些结果,描述自己做过什么,成绩怎 ...
- C++ web框架drogon 使用对象关系映射ORM(Object Relational Mapping)模式
在drogon框架之中,加入了ORM功能,使用在C++代码中嵌入很多的SQL语句,不仅让代码凌乱难看,更是需要很好的数据库语句编写功底,而使用ORM,则能够讲操作数据库转化为操作对象,在ORM中,通常 ...
- 轻量级KVO ——》 KVO 管理 observeValueForKeyPath
[转]http://joeyio.com/2013/10/21/lightweight_kvo/ 在这篇文章中,我会实现一个自己用的简单KVO类,我认为KVO非常棒,然而对于我大部分的使用场景来说,有 ...
- IOS筛选框的实现(仿糯米团)
实现效果: 低保真界面原型 代码讲解(创建部分) 1创建界面:初始化各种组件,搭建界面 #pragma mark- 初始化 :原点+高 - (instancetype)initWithOrigin:( ...
- IOS开发之自定义Button(集成三种回调模式)
前面在做东西的时候都用到了storyboard,在今天的代码中就纯手写代码自己用封装个Button.这个Button继承于UIView类,在封装的时候用上啦OC中的三种回调模式:目标动作回调,委托回调 ...
- Target-Action回调模式
前面的博客中提到过回调的概念,是在OC通过协议来实现的回调,和Java中的接口的回调极为相似,下面来介绍另一种方法回调模式: Target-Action回调.首先我们来从字面意思来理解一下Target ...
- target-action设计模式--主要为Button的方法重写
新建两个类MainViewController/ButtonView ButtonView.h #import <UIKit/UIKit.h> @interface ButtonView ...
最新文章
- 记录,一些jar包的作用
- Windows批处理(cmd/bat)常用命令
- 利用python对微信云数据库_如何用python看看女神的微信百度云里面有啥?
- elasticsearch使用more_like_this实现基于内容的推荐
- mysql 汉编码 的选_peewee连接mysql汉语言数据编码_mysql
- linux安装pl sql,Linux上安装配置InstantClient及64位系统Pl/SQL配置
- 千元内无敌!红米两款新机发布 小米9侧目?
- python支付宝自动支付_python-支付宝支付示例
- 远程部署SEP 11.RU5 安装包到 Windows 7 客户端提示“访问被拒”
- 语言编程思维陈萌_这本书告诉你,计算机为何能读懂人类语言,编程思维让你更聪明...
- 每天一个linux命令(56)--crontab命令
- 位平面提取 matlab,哪位高手知道图像位平面移位在Matlab中如何实现吗?[图像图形(图象)论坛]...
- vim YouCompleteMe
- 高等数学——伽马函数
- html表格里面嵌入按钮,bootstarp-table表格中嵌套多个BUTON按钮实现
- matlab 求傅里叶级数,MATLAB傅里叶级数.docx
- LA5713 秦始皇修路 (mst)
- 齐次方程与非齐次方程
- linux 设置用户有效天数,Linux用户管理:设置用户口令的使用期限
- 用百度搜索sb,第一个结果是??