UITextField を含む UIView がありますが、それらをクリックすると、キーボードを非表示にすることができず、「送信」ボタンがキーボードの後ろにあります。
どうすれば隠すことができますか?
ありがとう!
UITextField を含む UIView がありますが、それらをクリックすると、キーボードを非表示にすることができず、「送信」ボタンがキーボードの後ろにあります。
どうすれば隠すことができますか?
ありがとう!
Add UITextField's delegate method in your code.Don't forget to set the delegate.Whenever return key is keyboard is pressed this below method will be called. Also set its delegates:
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
[textField resignFirstResponder];
return YES;
}
EDIT : when once focused to textField and focus to other textfield, that textfield will not resign so do this as i assume from topmost u have textField1, textField2, textField3, textField4 if any more.... Add this delegate method.
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
if(textField == textField1) //motive resign other textFields
{
[textField2 resignFirstResponder];
[textField3 resignFirstResponder];
[textField4 resignFirstResponder];
}
else if(textField == textField2) //motive resign other textFields
{
[textField1 resignFirstResponder];
[textField3 resignFirstResponder];
[textField4 resignFirstResponder];
}
else if(textField == textField3) //motive resign other textFields
{
[textField1 resignFirstResponder];
[textField2 resignFirstResponder];
[textField4 resignFirstResponder];
}
else if(textField == textField4) //motive resign other textFields
{
[textField1 resignFirstResponder];
[textField2 resignFirstResponder];
[textField3 resignFirstResponder];
}
return YES;
}
EDIT U can use this also:
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
[self.view endEditing:YES];
return YES;
}
私はこのコードを使用します。このイベントは、ビュー内の任意の場所をタップすると実行され、textFields イベントに依存しません。
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [[event allTouches] anyObject];
if ([textField1 isFirstResponder] && [touch view] != textField1) {
[textField1 resignFirstResponder];
}
if ([textField2 isFirstResponder] && [touch view] != textField2) {
[textField2 resignFirstResponder];
}
...
[super touchesBegan:touches withEvent:event];
}