TextFieldDelegate

#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;
}

上一篇:1.素数判定(如何输出\n,\t,不用关键字冲突)


下一篇:sql server 字符串函数大全