RootView.m 中

    UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
button.frame = CGRectMake(100, 100, 100, 40);
[button setTitle:@"Target" forState:UIControlStateNormal];
[self addSubview:button]; // addTarget:self.controller 原来是 self
// 方法 RootViewButtonDidClicked 在 ViewController.m 里面实现
[button addTarget:self.controller action:@selector(RootViewButtonDidClicked:) forControlEvents:UIControlEventTouchUpInside];

RootView.h 中

设置属性

@property (nonatomic, assign)UIViewController *controller;

ViewController.m

// 点击事件
- (void)RootViewButtonDidClicked:(UIButton *)sender
{
NSLog(@"hello");
} - (void)viewDidLoad {
[super viewDidLoad]; // 设置控制器
self.rootView.controller = self; }

UI_Target/action 设计模式的更多相关文章

  1. UI基础:target...action设计模式,手势识别器.UIimageview

    使用target..action和delegate设计模式可以实现解耦.使代码更加优化. 手势识别器: 手势识别器:是对触摸事件做了封装,无需自己去判断某个手势是否触发,手势识别器本身起到了识别作用, ...

  2. UI:target-action设计模式、手势识别器

    ⼀.target/action设计模式 ⼆.代理设计模式 三.UIImageView 四.⼿势识别器 target/action设计模式 耦合是衡量⼀个程序写的好坏的标准之⼀, 耦合是衡量模块与模块之 ...

  3. UI 设计模式 手势识别器

    1> target / action 设计模式 : target ['tɑːgɪt]         1>什么是耦合 : 耦合是衡量一个程序呢写的好坏的标准之一 耦合是衡量模块与模块之间关 ...

  4. IOS开发基础知识--碎片45

    1:iOS SEL的简单总结 SEL就是对方法的一种包装.包装的SEL类型数据它对应相应的方法地址,找到方法地址就可以调用方法 a.方法的存储位置 在内存中每个类的方法都存储在类对象中 每个方法都有一 ...

  5. UI学习笔记---第五天

    target...action设计模式   代理设计模式   手势识别器 target...action设计模式 耦合是衡量一个程序写的好坏的标准之一,耦合是衡量模块与模块之间关联程度的指标 &quo ...

  6. UIController子类控件 UI_06

    1.UIImageView  是用来显示图片的控件,相当于相框,用来显示UIImage对象                //初始化UIImage对象及为其加载图片 //第一种方式 //    UII ...

  7. DesignModeler GestureRecgin…

    DesignModeler : 设计模式     GestureRecginzer:手势识别 作者:韩俊强 原创版权地址:http://blog.sina.com.cn/s/blog_814ecfa9 ...

  8. 设计模式之 外观模式详解(Service第三者插足,让action与dao分手)

    作者:zuoxiaolong8810(左潇龙),转载请注明出处,特别说明:本博文来自博主原博客,为保证新博客中博文的完整性,特复制到此留存,如需转载请注明新博客地址即可. 各位好,LZ今天给各位分享一 ...

  9. Java开发中的23种设计模式详解

    [放弃了原文访问者模式的Demo,自己写了一个新使用场景的Demo,加上了自己的理解] [源码地址:https://github.com/leon66666/DesignPattern] 一.设计模式 ...

随机推荐

  1. POJ 1273 Drainage Ditches(最大流Dinic 模板)

    #include<cstdio> #include<cstring> #include<algorithm> using namespace std; int n, ...

  2. 【LeetCode】Spiral Matrix(螺旋矩阵)

    这是LeetCode里的第54道题. 题目要求: 给定一个包含 m x n 个元素的矩阵(m 行, n 列),请按照顺时针螺旋顺序,返回矩阵中的所有元素. 示例 1: 输入: [ [ 1, 2, 3 ...

  3. 原生js实现 table表格列宽拖拽

    查看效果 <!DOCTYPE html> <html> <head> <meta charset="gbk"> <title& ...

  4. STM32F407 I2C 个人笔记

    源代码;https://github.com/YuQiao0303/STM32F407-Examples/tree/master/24.IIC 概述 I2C (IIC, Inter-Integrate ...

  5. ACdream 1135 MST

    MST Time Limit: 2000/1000MS (Java/Others) Memory Limit: 128000/64000KB (Java/Others) Problem Descrip ...

  6. pytorch中torch.unsqueeze()函数与np.expand_dims()

    numpy.expand_dims(a, axis) Expand the shape of an array. Insert a new axis that will appear at the a ...

  7. BZOJ 3611 [Heoi2014]大工程 ——虚树

    虚树第二题.... 同BZOJ2286 #include <map> #include <cmath> #include <queue> #include < ...

  8. [NOIP2009] 提高组 洛谷P1072 Hankson 的趣味题

    题目描述 Hanks 博士是 BT (Bio-Tech,生物技术) 领域的知名专家,他的儿子名叫 Hankson.现 在,刚刚放学回家的 Hankson 正在思考一个有趣的问题. 今天在课堂上,老师讲 ...

  9. ftrace笔记

    mount -t debugfs nodev /sys/kernel/debug 在mount后,可以在debug目录下看到tracing目录,该目录包含了ftrace的控制与输出文件. (1) en ...

  10. 模拟用户登录-SpringMVC+Spring+Mybatis整合小案例

    1. 导入相关jar包 ant-1.9.6.jarant-launcher-1.9.6.jaraopalliance.jarasm-5.1.jarasm-5.2.jaraspectj-weaver.j ...