前面博客有讲触摸事件提过响应事件和响应者链,而管理响应者链的正是UIResponder。

一、代码

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{

    NSLog(@"window:%@",[self.window nextResponder]);
    NSLog(@"AppDelegate: %@",[self nextResponder]);
    return YES;
}
//
//  ViewController.m
//  UIResponder
//
//  Created by cyw on 15-5-16.
//  Copyright (c) 2015年 cyw. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()<UITextFieldDelegate>

@end

@implementation ViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    UITextField *textField=[[UITextField alloc]init];
    textField.frame=CGRectMake(100, 100, 100, 40);
    textField.borderStyle=UITextBorderStyleLine;
    textField.backgroundColor=[UIColor redColor];
    textField.delegate=self;
    textField.tag=10001;
    BOOL canBecomeFirstResponder=[textField canBecomeFirstResponder     ];
    BOOL canResignFirstResponder=[textField canResignFirstResponder];
    NSLog(@"%d  %d",canBecomeFirstResponder,canResignFirstResponder);
    [textField becomeFirstResponder];
    [self.view addSubview:textField];

    UITextField *textField1=[[UITextField alloc]init];
    textField1.frame=CGRectMake(100, 200, 100, 40);
    textField1.borderStyle=UITextBorderStyleLine;
    textField1.backgroundColor=[UIColor redColor];
    textField1.delegate=self;
    textField1.tag=10002;
    [self.view addSubview:textField1];

     UIResponder *responder1= [textField nextResponder];
     UIResponder *responder2=[self nextResponder];
     UIResponder *responder3=[self.view nextResponder];
     NSLog(@"textField:%@\nViewController:%@\nself.view:%@",responder1,responder2,responder3);

}
- (void)textFieldDidBeginEditing:(UITextField *)textField
{
       BOOL isFirstResponder= [textField isFirstResponder];
        NSLog(@"textField%d isFirstResponder %d:",textField.tag,isFirstResponder);
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end

二、结果

2015-05-17 00:30:02.427 UIResponder[1132:60b] window:<UIApplication: 0x8d71b80>
2015-05-17 00:30:02.437 UIResponder[1132:60b] AppDelegate: (null)
2015-05-17 00:30:02.446 UIResponder[1132:60b] 1  1
2015-05-17 00:30:02.449 UIResponder[1132:60b] textField:<UIView: 0x8e742d0; frame = (0 0; 320 480); autoresize = RM+BM; layer = <CALayer: 0x8e739e0>>
ViewController:(null)
self.view:<ViewController: 0x8c9b8c0>
2015-05-17 00:30:02.463 UIResponder[1132:60b] textField10001 isFirstResponder 1:

三、由上面的输出结果有一点比较纳闷,为什么ViewController返回的是NULL?我想了半天也没想到什么原因,也请高手给指点一下

四、其实UIResponder不仅仅只有这些,具体可以参考:http://southpeak.github.io/blog/2015/03/07/uiresponder/?utm_source=tuicool

UIKit 框架之UIResponder的更多相关文章

  1. UIKit框架使用总结--看看你掌握了多少

    一.经常使用的,基本就是每次项目迭代都需要使用的 UIView.UILabel.UIImage.UIColor.UIFont.UIImageView.UITextField.UIButton. UIS ...

  2. Swift - 重写UIKit框架类的init初始化方法(以UITabBarController为例)

    原来写了篇文章讲UITabBarController的用法,当时是从UIViewController跳转到UITabBarController页面,代码如下: 1 self.presentViewCo ...

  3. UIKit框架

    在今后的应用程序构建中,会陆续使用各式各样的控件,因此UIKit框架的引入是必不可少的! 一.简介 UIKitk框架提供一系列的Class(类)来建立和管理iPhone OS应用程序的用户界面接口.应 ...

  4. iOS学习32之UIKit框架-可视化编程-XIB

    1. Interface Builder 可视化编程 1> 概述 GUI : 图形用户界面(Graphical User Interface, 简称GUI, 又称图形化界面) 是指采用图形方式显 ...

  5. 基础框架Fundation和UIkit框架的定义和使用

    Foundation 框架为所有应用程序提供基本的系统服务 您的应用程序以及 UIKit 和其他框架,都建立在 Foundation 框架的基础结构之上.Foundation 框架提供许多基本的对象类 ...

  6. iOS开发概述UIkit动力学,讲述UIKit的Dynamic特性,UIkit动力学是UIkit框架中模拟真实世界的一些特性。

    转发:http://my.oschina.net/u/1378445/blog/335014 iOS UIKit动力学 Dynamics UIAttachmentBehavior 实现iMessage ...

  7. iOS开发UIKit框架-可视化编程-XIB

    1. Interface Builder 可视化编程 1> 概述 GUI : 图形用户界面(Graphical User Interface, 简称GUI, 又称图形化界面) 是指采用图形方式显 ...

  8. 79、iOS 的Cocoa框架、Foundation框架以及UIKit框架

    Cocoa框架是iOS应用程序的基础 1. Cocoa是什么? Cocoa是 OS X和ios 操作系统的程序的运行环境. 是什么因素使一个程序成为Cocoa程序呢?不是编程语言,因为在Cocoa开发 ...

  9. UIKit 框架之UIView二

    下面这些都是UIView一些基本的东西,具体的可以参考UIKit 框架之UIView一博客 一.自定义一个View // // MyView.m // UIView // // Created by ...

随机推荐

  1. hive 实现类似 contain 包含查询

    如何用hive sql 实现 contain 查询? 需求:判断某个字符串是否在另一个字符串中? 方法: 可以自定义函数,但是用正则匹配regexp更方便 代码如下: 首先,查看regexp正则函数的 ...

  2. Spring中注入bean学习的总结

    1.在类上直接加注解@Component,那么这个类就直接注入到Spring容器中了  ,像@Contrloller,@Service这些本质上都是@Component, 2.@Configurati ...

  3. CopyOnWriteArrayList源码解析(2)

    此文已由作者赵计刚授权网易云社区发布. 欢迎访问网易云社区,了解更多网易技术产品运营经验. 5.删除元素 public boolean remove(Object o) 使用方法: list.remo ...

  4. [leetcode.com]算法题目 - Gray Code

    The gray code is a binary numeral system where two successive values differ in only one bit. Given a ...

  5. 【BZOJ2002】 [Hnoi2010]Bounce 弹飞绵羊

    BZOJ2002 [Hnoi2010]Bounce 弹飞绵羊 Solution 很早以前写的一道分块题,最近在搞LCT,又做了一遍. 1.LCT做法 看到这种动态修改,想下LCT怎么维护. 修改操作就 ...

  6. python 通过pytz模块进行时区的转换,获取指定时区的时间

    import pytz import time import datetime print(pytz.country_timezones('cn')) # 查询中国所拥有的时区 print(pytz. ...

  7. 杀掉所有 skynet 进程

    ps aux | grep skynet | awk '/config/{print $2}' | xargs kill

  8. DES/3DES/AES区别

    公元前400年,古希腊人发明了置换密码.1881年世界上的第一个电话保密专利出现.在第二次世界大战期间,德国军方启用“恩尼格玛”密码机,密码学在战争中起着非常重要的作用. DES 1977年1月,美国 ...

  9. [HTML] css3 输入框input类型为number时,去掉上下箭头方式

    <input type="number" ...> <style> input::-webkit-outer-spin-button, input::-we ...

  10. RegexHelper.js

    var Validator = { VerityLib: { //验证字符串非空 IsNotEmpty: function (input) { if (input != '') { return tr ...