前面博客有讲触摸事件提过响应事件和响应者链,而管理响应者链的正是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. CxGrid鼠标移到更改颜色

    CxGrid鼠标移到更改颜色 设置表单中TcxGrid1DBTableView的Styles属性,设置Selection procedure TForm1.cxGrid1DBTableView1Mou ...

  2. ios调用系统界面显示英文

    调用系统相册界面 UIImagePickerController *picker = [[UIImagePickerController alloc] init]; picker.sourceType ...

  3. iOS之UITextField限制字数

    解决方法:根据UITextField本身提供的事件监听: [textField addTarget:self action:@selector(textFieldDidChange:) forCont ...

  4. SQL关闭自增长列标识:SET IDENTITY_INSERT

    关闭自增长列添加记录,然后再恢复自增长功能 SET IDENTITY_INSERT 表名 ON; inert ,); SET IDENTITY_INSERT 表名 OFF

  5. WPF用户控件库 嵌入外部(VLC)exe

    综合网上资源完成的自己的第一篇博客 ------------------------------------------------------------------------ 网上类似的贴子挺多 ...

  6. DOM扩展:DOM API的进一步增强[总结篇-下]

    本文承接<DOM扩展:DOM API的进一步增强[总结篇-上]>,继续总结DOM扩展相关的功能和API. 3.6 插入标记 DOM1级中的接口已经提供了向文档中插入内容的接口,但是在给文档 ...

  7. AJPFX:什么是止盈?什么是止损?

    在您进行外汇交易后,会碰到Take Profit(止盈)和 Stop Loss(止损)这两个词,均是用作控制风险的工具. 止盈(Take Profit):当单子达到预期的获利价格时锁定盈利.当订单在盈 ...

  8. MariaDB 存储过程与函数(10)

    MariaDB数据库管理系统是MySQL的一个分支,主要由开源社区在维护,采用GPL授权许可MariaDB的目的是完全兼容MySQL,包括API和命令行,MySQL由于现在闭源了,而能轻松成为MySQ ...

  9. Ms17-010进行WEB提权之实践下某培训靶机服务器

    前言:该机器为某个其他培训机构的靶机,说实话在这里没炫耀啥,只是给各位学习Ms17010的同学指一条路,我原先也折腾这玩意儿好久,但是就是不行,最近才找到了出路,所以多写两篇文章,把各种需要注意的地方 ...

  10. ubuntu下wps无法使用搜狗输入法输入中文

    sudo vim /usr/bin/et sudo vim /usr/bin/wps sudo vim /usr/bin/wpp 以上三个文件,都加入如下内容后重新打开文档即可 export XMOD ...