六狼论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博账号登陆

只需一步,快速开始

搜索
查看: 97|回复: 0

点击空白处取消UITextField第一响应

[复制链接]

升级  66%

127

主题

127

主题

127

主题

举人

Rank: 3Rank: 3

积分
398
 楼主| 发表于 2013-1-4 01:37:10 | 显示全部楼层 |阅读模式
<div id="cnblogs_post_body">点击View的空白处UITextField取消第一响应
在学习的时候会遇到这个问题,点击空白处取消了UITextField的第一响应
http://www.hopean.com
更多阅读请访问http://www.hopean.com
相关代码如下:
在viewDidLoad中创建UITextField
textFieldDemo = [[UITextField alloc] initWithFrame:CGRectMake(0, 150, 130, 30)];    textFieldDemo.backgroundColor = [UIColor brownColor];    textFieldDemo.secureTextEntry = YES;    textFieldDemo.keyboardType = UIKeyboardTypeURL;    //textFieldDemo.returnKeyType = YES;    [textFieldDemo setPlaceholder:@"UserName"];        //UIReturnKeySearch        textFieldDemo.delegate = self;    [self.view addSubview:textFieldDemo];




相关方法
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{    [textFieldDemo resignFirstResponder];    }- (void)textFieldDidEndEditing:(UITextField *)textField{    textFieldDemo = textField;    [textField resignFirstResponder];}//-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation//{//    return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);//}- (BOOL)textFieldShouldEndEditing:(UITextField *)textField{    return YES;}- (BOOL)textFieldShouldReturn:(UITextField *)textField{    return YES;}
您需要登录后才可以回帖 登录 | 立即注册 新浪微博账号登陆

本版积分规则

快速回复 返回顶部 返回列表