iphone之控件、控件事件与OC代码关联
2012-12-02 17:04
351 查看
ios中对应的控件(文本控件、按钮控件等)、控件事件(点击、拖动),两者的类型都非常多。 笔者以文本控控件、按钮事件来介绍它们与OC代码的关联。
我以下图为例,当鼠标点击按钮式,文本框显示“Hello Word.”
按钮点击回调函数注册
通过xib试图,以按钮为始,以File's Owner为终在提示的小窗口选取对应的回调函数
文本框与OC中UITextField关联
首先要定义UITextField为IBoutle类型。
然后以File's Owner为始,以按钮为终,在提示的小窗口选取对应的控件
主要代码:
Hello_WorldViewController.h
Hello_WorldViewController.m
我以下图为例,当鼠标点击按钮式,文本框显示“Hello Word.”
按钮点击回调函数注册
通过xib试图,以按钮为始,以File's Owner为终在提示的小窗口选取对应的回调函数
文本框与OC中UITextField关联
首先要定义UITextField为IBoutle类型。
然后以File's Owner为始,以按钮为终,在提示的小窗口选取对应的控件
主要代码:
Hello_WorldViewController.h
// // Hello_WorldViewController.h // Hello World // // Copyright __MyCompanyName__ 2012. All rights reserved. // #import <UIKit/UIKit.h> @interface Hello_WorldViewController : UIViewController { UITextField *txtField; } @property (nonatomic, retain) IBOutlet UITextField *txtField; -(IBAction)onClickButton:(id)sender; @end
Hello_WorldViewController.m
// // Hello_WorldViewController.m // Hello World // // Copyright __MyCompanyName__ 2012. All rights reserved. // #import "Hello_WorldViewController.h" @implementation Hello_WorldViewController @synthesize txtField; -(IBAction)onClickButton:(id)sender { //txtField.text = @"Hello World."; NSString *str = [[NSString alloc] initWithFormat:@"Hello. %@", txtField.text]; UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Hello!" message:str delegate:self cancelButtonTitle:@"Done" otherButtonTitles:nil]; [alert show]; [alert release]; [str release]; } /* // The designated initializer. Override to perform setup that is required before the view is loaded. - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { if ((self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil])) { // Custom initialization } return self; } */ /* // Implement loadView to create a view hierarchy programmatically, without using a nib. - (void)loadView { } */ /* // Implement viewDidLoad to do additional setup after loading the view, typically from a nib. - (void)viewDidLoad { [super viewDidLoad]; } */ /* // Override to allow orientations other than the default portrait orientation. - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { // Return YES for supported orientations return (interfaceOrientation == UIInterfaceOrientationPortrait); } */ - (void)didReceiveMemoryWarning { // Releases the view if it doesn't have a superview. [super didReceiveMemoryWarning]; // Release any cached data, images, etc that aren't in use. } - (void)viewDidUnload { // Release any retained subviews of the main view. // e.g. self.myOutlet = nil; self.txtField = nil; } - (void)dealloc { [txtField dealloc]; [super dealloc]; } @end
相关文章推荐
- iPhone开发学习笔记001——Xib界面上的控件与代码的相互关联方法
- iPhone开发学习笔记001——Xib界面上的控件与代码的相互关联方法
- iPhone开发学习笔记001——Xib界面上的控件与代码的相互关联方法
- iphone开发-用代码显示控件
- Android中RecyclerView的item中控件的点击事件添加删除一行、上移下移一行的代码实现
- UpdatePanel中用后台CS代码调用JS代码,先执行控件事件,后触发JS
- 给通过代码创建的控件关联消息映射
- IOS 代码创建控件,并有处理事件
- 章鱼哥—VB.NET 如何实现代码自动生成控件 添加绑定事件
- javascript练习:8-5事件与处理代码关联
- 一个WinForm记事本程序(包含主/下拉/弹出菜单/打开文件/保存文件/打印/页面设置/字体/颜色对话框/剪切版操作等等控件用法以及记事本菜单事件/按键事件的具体代码)
- 关于点击事件提交代码到后台发现控件被重置的问题
- iphone上一些常用控件代码实现方式(原创)
- Android IOC 之 注解绑定控件 以及事件 事例 代码简单注释讲解
- asp.net 服务器控件LinkButton等在后台代码中设置js事件或添加css样式
- iOS开发中oc代码响应js网页点击事件的方法
- bootstrap 事件shown.bs.modal用于监听并执行你自己的代码【写hostmanger关联部门遇到的问题及解决方法】
- 演示事件(Event)怎样使用以及怎样为用户控件添加一个事件(示例代码下载)
- Android中RecyclerView的item中控件的点击事件添加删除一行、上移下移一行的代码实现
- Android 使用代码主动去调用控件的点击事件(模拟人手去触摸控件)