iphone的responder chain及interface builder中First Responder的使用方法
来源:互联网 发布:淘宝网买qq号安全吗 编辑:程序博客网 时间:2024/05/22 09:08
http://www.devdiv.com/thread-30694-1-1.html
我们先看一张图,看看event被处理的顺序
The general path of an event up the responder chain starts with a view—the first responder or the view under the mouse pointer or finger. From there, it proceeds up the view hierarchy to the window object and then to the global application object. However, the responder chain for events in iOS adds a variation to this path: If a view is managed by a view controller and if the view cannot handle an event, the view controller becomes the next responder.(如果一个视图被一个视图控制器管理着并且这个视图处理不了某个事件,则这个视图控制器就成为这个事件的下一级响应)
一般来说first responder就是主表或者指头触摸到的控件。
iphone中,responder chain为view->(view controller->)parent view(->parent view controller)->window->application。
The general path of an event up the responder chain starts with a view—the first responder or the view under the mouse pointer or finger. From there, it proceeds up the view hierarchy to the window object and then to the global application object. However, the responder chain for events in iOS adds a variation to this path: If a view is managed by a view controller and if the view cannot handle an event, the view controller becomes the next responder.(如果一个视图被一个视图控制器管理着并且这个视图处理不了某个事件,则这个视图控制器就成为这个事件的下一级响应)
一般来说first responder就是主表或者指头触摸到的控件。
iphone中,responder chain为view->(view controller->)parent view(->parent view controller)->window->application。
1. 建立一个view-based application,名字为view1
2. 双击view1ViewController.xib
3. 在interface builder中选中first reponder
点菜单tools->identity inspector
在identity inspector中新加一个action,名字叫myAction1
4. 在interface builder中选中button
5. 点菜单tools->connection inspector, 点中touch up inside拖拽到first responder
并且选中myAction1
6. 点击执行,点button,你会发现没有任何响应
7. 在view1ViewController.h中加入
- (IBAction) myAction1:(id)event;
在view1ViewController.m中加入
- (IBAction) myAction1:(id)event{ UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Hello DevDiv" message:@"I'm a DevDiver" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil]; [alertView show]; [alertView release];}
8. 重新编译执行,点击button
现在大家知道responder chain作用了吧。
button的first responder是它自己,当它不能处理某一action后,它就交给responder chain中的controller来处理。
另外,大家也明白了interface builder中First Responder怎么使用了吧。
- iphone的responder chain及interface builder中First Responder的使用方法
- iphone的responder chain
- responder chain
- first responder与小键盘之间的关系
- first responder
- Responder
- 关于File's Owner, First Responder, Application Delegate的解释
- 对xib/nib, file's owner, first responder的理解
- 对xib/nib, file's owner, first responder的理解
- 对xib/nib, file's owner, first responder的理解
- 对xib/nib, file's owner, first responder的理解
- 对xib/nib, file's owner, first responder的理解
- xib 种的file's owner&& First Responder
- IOS Responder Chain简析
- Responder Chain简析
- nextResponder与Responder Chain
- The Responder Chain
- Responder Chain简析
- 在亚马逊网上注册kindle 3及下载免费电子图书的步骤
- eWebEditor-在线HTML编辑器控件
- java之jdom处理xml
- 一个Java程序员应该掌握的10项技能
- 性能监控之监控SQL语句
- iphone的responder chain及interface builder中First Responder的使用方法
- tomcat server.xml配置详解
- 同时向两个表中增加记录,其中有关联为自增字段。
- SGU 134 Centroid
- 【ASP.NET】 弹出消息框
- 免安装版Tomcat6.0启动方法
- MySql5.1参考手册
- Timer无刷新定时器
- Java 回调函数实现方式