首页 > 其他 > 详细

TextFieldDelegate

时间:2015-10-22 23:49:25      阅读:226      评论:0      收藏:0      [点我收藏+]

#import "AppDelegate.h"

@interface AppDelegate ()<UITextFieldDelegate>

@end

@implementation AppDelegate


/*

 回收键盘的步骤
 1、遵守UITextFieldDelegate协议
 2、创建UITextField对象
 3、设置UITextField对象的delegate属性为AppDelegate
 4、实现UITextFieldDelegate的textFieldShouldReturn:方法
 5、在textFieldShouldReturn:方法取消textField作为第一响应者
 */

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    //创建一个UIWindow对象
    self.window = [[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds];
    self.window.backgroundColor = [UIColor whiteColor];
    [self.window makeKeyAndVisible];
    //创建一个UITextField对象
    UITextField *text = [[UITextField alloc]initWithFrame:CGRectMake(100, 100, 100, 30)];
    text.backgroundColor = [UIColor redColor];
    [self.window addSubview:text];
    text.delegate = self;
    return YES;
}
//实现textFieldDelegate的textFieldShouldReturn:方法
- (BOOL)textFieldShouldReturn:(UITextField *)textField{
    [textField resignFirstResponder];
    return YES;
}

TextFieldDelegate

原文:http://www.cnblogs.com/chen-en-ni66/p/4903048.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!