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模式 回调相关推荐

  1. 通过 Windows 用户模式回调实施的内核攻击

    这篇文章翻译自一篇多年之前的论文,原文作者是 Tarjei Mandt.原文系统地描述了 win32k 的用户模式回调机制以及相关的原理和思想,可以作为学习 win32k 漏洞挖掘的典范.早前曾经研读 ...

  2. UI一揽子计划 5 (Target: Action:  、Protocol   Delegate、 UIImageView 、手势识别器)

    一.target/ action 设计模式      耦合是衡量⼀一个程序写的好坏的标准之一,      耦合是衡量模块与模块之间关联程度的指标      "高内聚,低耦合"是⾯面 ...

  3. STAR-Situation\Target\Action\Result

    STAR STAR是SITUATION(背景).TASK(任务).ACTION(行动)和RESULT(结果)四个英文字母的首字母组合. 通常,应聘者求职材料上写的都是一些结果,描述自己做过什么,成绩怎 ...

  4. C++ web框架drogon 使用对象关系映射ORM(Object Relational Mapping)模式

    在drogon框架之中,加入了ORM功能,使用在C++代码中嵌入很多的SQL语句,不仅让代码凌乱难看,更是需要很好的数据库语句编写功底,而使用ORM,则能够讲操作数据库转化为操作对象,在ORM中,通常 ...

  5. 轻量级KVO ——》 KVO 管理 observeValueForKeyPath

    [转]http://joeyio.com/2013/10/21/lightweight_kvo/ 在这篇文章中,我会实现一个自己用的简单KVO类,我认为KVO非常棒,然而对于我大部分的使用场景来说,有 ...

  6. IOS筛选框的实现(仿糯米团)

    实现效果: 低保真界面原型 代码讲解(创建部分) 1创建界面:初始化各种组件,搭建界面 #pragma mark- 初始化 :原点+高 - (instancetype)initWithOrigin:( ...

  7. IOS开发之自定义Button(集成三种回调模式)

    前面在做东西的时候都用到了storyboard,在今天的代码中就纯手写代码自己用封装个Button.这个Button继承于UIView类,在封装的时候用上啦OC中的三种回调模式:目标动作回调,委托回调 ...

  8. Target-Action回调模式

    前面的博客中提到过回调的概念,是在OC通过协议来实现的回调,和Java中的接口的回调极为相似,下面来介绍另一种方法回调模式: Target-Action回调.首先我们来从字面意思来理解一下Target ...

  9. target-action设计模式--主要为Button的方法重写

    新建两个类MainViewController/ButtonView ButtonView.h #import <UIKit/UIKit.h> @interface ButtonView ...

最新文章

  1. 记录,一些jar包的作用
  2. Windows批处理(cmd/bat)常用命令
  3. 利用python对微信云数据库_如何用python看看女神的微信百度云里面有啥?
  4. elasticsearch使用more_like_this实现基于内容的推荐
  5. mysql 汉编码 的选_peewee连接mysql汉语言数据编码_mysql
  6. linux安装pl sql,Linux上安装配置InstantClient及64位系统Pl/SQL配置
  7. 千元内无敌!红米两款新机发布 小米9侧目?
  8. python支付宝自动支付_python-支付宝支付示例
  9. 远程部署SEP 11.RU5 安装包到 Windows 7 客户端提示“访问被拒”
  10. 语言编程思维陈萌_这本书告诉你,计算机为何能读懂人类语言,编程思维让你更聪明...
  11. 每天一个linux命令(56)--crontab命令
  12. 位平面提取 matlab,哪位高手知道图像位平面移位在Matlab中如何实现吗?[图像图形(图象)论坛]...
  13. vim YouCompleteMe
  14. 高等数学——伽马函数
  15. html表格里面嵌入按钮,bootstarp-table表格中嵌套多个BUTON按钮实现
  16. matlab 求傅里叶级数,MATLAB傅里叶级数.docx
  17. LA5713 秦始皇修路 (mst)
  18. 齐次方程与非齐次方程
  19. linux 设置用户有效天数,Linux用户管理:设置用户口令的使用期限
  20. 用百度搜索sb,第一个结果是??

热门文章

  1. CP2102和CP2104的区别
  2. 今日收获 --- 场景中大量集合体的优化
  3. 闺蜜的电脑桌面总是杂乱无章,实在看不下去了。用Python实现一键实现自动分类管理文件。
  4. Win11电脑桌面的图标变成白色了怎么解决?
  5. 高端喷绘的基本知识和经验
  6. 今日财富杂志今日财富杂志社今日财富编辑部2022年第21期目录
  7. shell 读取csv文件
  8. NNG/NanoMsg进程线程间通讯库
  9. Protobuf 介绍与实战9:将消息编译成不同语言版本的类库
  10. 解决vc2017不能建立对话框类的问题