We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
loadView内代码创建了一个textField,头文件内并没有声明 添加到view中
然后需要对呼出的键盘做一下关闭功能的配置 网上找了一圈,差不多就是在两种场景下需要关闭键盘 一是点击键盘上的return键,一是点击textField以外的区域
- (BOOL)textFieldShouldReturn:(UITextField *)textField { [textField resignFirstResponder]; return YES; }
// 触摸背景,关闭键盘 - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { UITouch *touch = [touches anyObject]; UIView *view = (UIView *)[touch view]; NSLog(@"touch"); if(view == self.view){ // 如果textField使用局部对象,这里就需要采用ViewWithTag的方式来取到textView。从前端的角度来说可能是类似于dom选择器。 // 更好的方法是将textField控件再头文件进行声明。这样性能更好,代码简洁 // [self.textField resignFirstResponder]; } }
The text was updated successfully, but these errors were encountered:
// 触摸背景,关闭键盘 - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { UITouch *touch = [touches anyObject]; UIView *view = (UIView *)[touch view]; NSLog(@"touch"); if(view == self.view){ [self.textField resignFirstResponder];//第一种方法,再头文件中声明成全局控件 //[[self.view.subviews objectAtIndex:3] resignFirstResponder];//第二种方法,找到subViews数组中对应的view索引 /* 第三种方法 遍历subviews找到UITextField类型的view * http://stackoverflow.com/questions/10395690/clear-uitextfield-data-when-coming-to-that-page-again-iphone */ /* NSArray *arraysubViews = [self.view subviews]; for(UIView *subView in arraysubViews){ if([subView isKindOfClass:[UITextField class]]){ [subView resignFirstResponder]; } } */ } }
Sorry, something went wrong.
No branches or pull requests
loadView内代码创建了一个textField,头文件内并没有声明
添加到view中
然后需要对呼出的键盘做一下关闭功能的配置
网上找了一圈,差不多就是在两种场景下需要关闭键盘
一是点击键盘上的return键,一是点击textField以外的区域
The text was updated successfully, but these errors were encountered: