我正在开发一个应用程序,我从自定义视图(而不是输入视图)输入数据到文本字段。问题是我不想在触摸文本字段时弹出系统键盘。我已经通过{{ 3}}但是无法找到解决方案。如何实现这一点。
答案 0 :(得分:4)
您也可以使用手势
- (void)viewDidLoad {
[super viewDidLoad];
UITapGestureRecognizer *gestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(hideKeyboard)];
gestureRecognizer.cancelsTouchesInView = NO;
[self.view addGestureRecognizer:gestureRecognizer];
}
- (void)hideKeyboard {
[self.view endEditing:YES];
}
答案 1 :(得分:3)
试试这段代码可以帮到你
-(BOOL)textFieldShouldBeginEditing:(UITextField *)textField{
if (textField==/**urs testField on which you want to remove keyboard on click*/ ) {
[textField resignFirstResponder];
//*its depend your requirement
[here you can call yours custom view];
}
return YES;
}
根据要求进行调整..
答案 2 :(得分:2)
设置userInteractionEnabled属性:
//UITextField *text;
text.userInteractionEnabled = NO;
答案 3 :(得分:1)
不确定,你到底在想什么。我希望您需要处理UITextField
代理但不需要UIKeyboard
:如果是,请执行<{p}}
delegate
答案 4 :(得分:1)
将IBOutlet属性分配给该特定的UITextField
然后在viewDidLoad中添加以下代码[self.YourUITextField setUserInteractionEnabled:NO];
答案 5 :(得分:1)
禁用特定字段的编辑
-(BOOL)textFieldShouldBeginEditing:(UITextField *)textField{
if ([textField isEqual:myTextField]) {
return NO;
}
return YES;
}
答案 6 :(得分:1)
-(BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
[self.view endEditing:YES]; // this statement will hide keyboard. Useful when we use many textfields based on tag value.
return YES;
}