iphone之控件、控件事件与OC代码关联
来源:互联网 发布:中国汽车出口现状知乎 编辑:程序博客网 时间:2024/05/21 23:35
ios中对应的控件(文本控件、按钮控件等)、控件事件(点击、拖动),两者的类型都非常多。 笔者以文本控控件、按钮事件来介绍它们与OC代码的关联。
我以下图为例,当鼠标点击按钮式,文本框显示“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之控件、控件事件与OC代码关联
- swift开发iOS应用之label控件与代码关联
- ActiveX之控件关联变量、调用事件
- iPhone开发学习笔记001——Xib界面上的控件与代码的相互关联方法
- iPhone开发学习笔记001——Xib界面上的控件与代码的相互关联方法
- iphone之iphone控件尺寸
- iPhone控件之UIScrollView
- iPhone控件之UIScrollView
- 布局控件与地图控件关联
- OC之基本控件一
- OC之基本控件二
- OC之基本控件三
- OC之基本控件四
- OC之基本控件五
- 变量与控件像关联
- iPhone开发【四】常用控件之ActionSheet与AlertView
- iPhone开发【四】常用控件之ActionSheet与AlertView
- iphone常用控件之UIScrollView
- 最适合单挑的前十名人物攻略
- 文功武勋是什么,如何获得武勋?
- C++中#define的用法
- 用C++实现栈
- 牌堆总结和记牌技巧解析
- iphone之控件、控件事件与OC代码关联
- mac osx 10.8.2编译mod_wsgi的问题修复
- 三国杀3v3模式最好的组合
- C++ Placement New
- Linux Shell编程入门
- C语言链栈实现
- AT&T 汇编语言学习笔记一
- 手机报IN语
- HDU 4476 Cut the rope