IOS Note - Outlet(插座) & Action(动作)
2024-08-21 19:35:48
OutletActionViewController.h
#import <UIKit/UIKit.h> @interface OutletActionViewController : UIViewController
{
IBOutlet UITextField *txtName;
} // expose the outlet as a property
@property (nonatomic, retain) UITextField *txtName; // declare the action
- (IBAction) btnClicked: (id) sender; @end
OutletActionViewController.m
#import "OutletActionViewController.h" @implementation OutletActionViewController // synthesize the property
@synthesize txtName; // display text of the textbox in the alert
- (IBAction) btnClicked: (id) sender {
NSString *str =
[[NSString alloc] initWithFormat: @"Hello, %@", txtName.text]; UIAlertView *alert =
[[UIAlertView alloc]
initWithTitle: @"Hello"
message: str
delegate: self
cancelButtonTitle: @"OK"
OtherButtonTitles: nil]; [alert show];
[str release];
[alert release];
} - (void) dealloc {
// release the outlet
[txtName release];
[super dealloc];
}
如何添加关联
-------------------------------------------------------------------------------------------
Outlet添加:
按Control同时将File's Owner拖放到IBOutlet在视图中所在的对象(eg: Text Field)
File's Owner --> Outlet
Action添加:
按Control同时将事件需要触发的控件(eg: Round Rect Button)拖放到File's Owner
选择动作的指定函数
Action --> File's Owner
最新文章
- 《徐徐道来话Java》(2):泛型和数组,以及Java是如何实现泛型的
- 如何在Webstorm/Phpstorm中设置连接FTP,并快速进行文件比较,上传下载,同步等操作
- Java基础-输入输出-3.编写BinIoDemo.java的Java应用程序,程序完成的功能是:完成1.doc文件的复制,复制以后的文件的名称为自己的学号姓名.doc。
- angular之自定义过滤器的使用
- HDU 1695
- (C/C++) 基础问答题
- C++ 中类的构造函数理解(二)
- POJ 1068 AC 2014-01-07 15:24 146人阅读 评论(0) 收藏
- Makefile学习与进阶之Makefile.am和$$(M)的意思
- PHP单例模式编写
- Xcode升级7.3 自动补全不提示导入的自定义类解决方案
- Swift - 使用UI Dynamics给UIKit组件添加重力和碰撞行为
- Adobe After Effects 2017-14.0安装教程
- Centos 7.3 安装mysql5.7.19 各种调试就不多说了
- MVC中使用Echart后台加载数据 实现饼图、折线图、全国地图数据,单击双击事件等
- Web报表工具FineReport二次开发JS之字符串
- typecho设置文章密码保护
- Node.js 事件循环机制
- KAFKA跨主机部署网络不通解决思路
- bzoj千题计划269:bzoj2655: calc (拉格朗日插值)