resignFirstResponder makes field lose focus but keyboard doesn't disappear - iphone

I call resignFirstResponder for my textField, it returns YES, but the keyboard does not disappear. I tried many variations and tips, but nothing helped.
May have an idea why this is possible?
I repeat, the method works, the field loses focus, but the keyboard does not disappear
I use iOS 4.3.
UPD:
if([self.securedTextView.passField isFirstResponder]){
if([self.securedTextView.passField canResignFirstResponder]){
[self.securedTextView.passField resignFirstResponder];
}
}
and [self.securedTextView.passField resignFirstResponder]; returns YES, but the keyboard is still on the screen...

you can use UITextField delegate methods explained below..and Try using this..
-(BOOL)textFieldShouldReturn:(UITextField *)textField {
[textField resignFirstResponder];
return YES;
}
Happy Coding...

Related

is it possible to disable keyboad(UITextField) without hidding?

I'd like to disable UITextField's keyboard without hidding.
is it possible?
If it's so, could you show me how to do?
thanx
Carsh
if you implement delegate method of uitextfield
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
return NO;
}
It does not show the keyboard.
I don't believe the UIKeyboard can be disabled without hiding it.
If you'd like to disable user interaction with the keyboard, you could add an extra UIWindow on top of your existing windows.
By overlaying the UIKeyboard with a transparent UIWindow, the user would be able to see the keyboard, without interacting with it.
a haha , i have a very very ugly method. you can creat a view whichs frame = the keyboards frame. [view setBackgroundColor:[UIColor clearColor]]; [self addSubviews:view];
I did not try but this should work:
textField.inputView.userInteractionEnabled = NO;

Weird keyboard behavior in my iOS app

Ok, so here's how my keyboard behaves:
There's a button which calls a method to send a textmessage, that works fine. If the user now sends the text everything's fine.
Now if (s)he taps cancel it switches back to my view (as it's supposed to do), but the keyboard won't show up. I already tried
- (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result {
[self dismissModalViewControllerAnimated:YES];
[inputView becomeFirstResponder];
}
since it didn't work I tried:
-(void)viewDidAppear:(BOOL)animated{
[inputView becomeFirstResponder];
}
but that won't work either. So how can I get my keyboard to show up?
EDIT: inputText is an UITextView.
This might be related to sending YES in dismissModalViewControllerAnimated:. When animations are involved, statements generally don't remain synchronous. So, your call to [inputView becomeFirstResponder] must be executing before the modal dialog has been dismissed, resulting in an inconsistent state. This is the reason why the inputView does not take focus.
HTH,
Akshay

Keyboard won't dismiss when popover closes on iOS 3.2

- (BOOL)popoverControllerShouldDismissPopover:(UIPopoverController *)popoverController {
[self dismissFirstResponder];
return YES;
}
-(void)dismissFirstResponder {
[nameField resignFirstResponder];
[descriptionField resignFirstResponder];
[helpField resignFirstResponder];
}
I have tried loads of different things, but the keyboard just isn't going down:
I checked to see if my outlets were hooked up correctly in Interface Builder
I put breakpoints inside the 2 methods to check they were being called at the appropriate times, and they were. Those 3 Text Fields are the only ones in the app.
What happens: The popover gets dismissed but the keyboard stays up.
I would really appreciate some help on this matter. It might be a known bug on iOS 3.2, if so any workarounds would be gratefully accepted. Thanks
Make sure the delegate for UITextView the UITextField is assigned
Then call the following method to dismiss any keyboard activity from the view.
[self.view endEditing:YES];

UITextField resign first responder iOS4

I have a simple piece of code that works on every system except iOS4.
It's about resigning first responder for a UITextField. The text field is all wired up, and here's the code for the delegate:
- (BOOL)textFieldShouldReturn:(UITextField *)textField{
[opis resignFirstResponder];
return YES;
}
I've tried it almost every possible way, trying to return NO as well and it doesn't work. The weirdest thing is that it DOES work on every iphone OS before 4.0 and on iPad as well (tested in simulators and on actual devices)
Can anyone help?
This worked with my 3GS in iOS4. Are you sure you properly set the UITextField delegate?
- (BOOL) textFieldShouldReturn:(UITextField*)textField {
[textField resignFirstResponder];
return YES;
}
Not sure if this is similar to your case, but I have a UITextField in a UIAlertView and HAD a similar problem with keyboard not dismissing on resignFirstResponder.
Here was my solution:
- (BOOL)textFieldShouldReturn:(UITextField *)textField {
[textField resignFirstResponder];
[alert resignFirstResponder];
return YES;
}
It seems that the alert became firstResponder after textfield resigned.
This is a very classic problem. I assume you are setting the delegate to your textField but the question is where? Are you setting in the initWithNib... initializer of your controller? Than that is wrong. Because your text field is not initialized by then. Its initialize in viewDidLoad method, so you should set your delegate there and it should work.

iPhone - Problem with UITextView

This is probably an easy thing to do, but I just can't figure it out - how do I end editing athe textview? how can I get the keyboard to disappear? or do I have to click outside it to make it go away?
First, a (to be honest) fairly simple question like this makes me wonder if you've tried reading the documentation, or searching on the internet.
Searching for "Apple documentation UITextView" gives you this link to the class documentation. Similarly, here is the documentation for the UITextViewDelegate.
Searching for "UITextView simple example" gives you this useful example.
Searching for "UITextView dismiss keyboard", the first hit seems to answer your question exactly. (Although he dismisses the keyboard on a return key, which may not be what you want.) (Edit - it seems from your second comment it's exactly what you want.)
P.S. The people above are correct, if a little terse (understandably). You need to implement a UITextViewDelegate. In that delegate, if you want to hide the keyboard on a return key, implement shouldChangeTextInRange, look for a #"\n" and resign first responder if you get it. Alternatively, add a "Done editing" button to your UI, and resign first responder if the user presses it.
Very Easy:
[myTextField resignFirstResponder];
will do the trick.
One way to end editing, tapping outside the textView, is not entirely trivial. Selecting other text views or text fields or activating a navigation control will trigger...
- (void)textViewDidEndEditing:(UITextView *)textView
...on whatever object you've designated as the textView's delegate. You can trigger this yourself by calling...
- (BOOL)endEditing:(BOOL)force
...on the view that contains your text field.
Suppose I have a UITextView inside a UITableViewCell (inside a UITable). I want to enable editing to end by tapping the table. I could do this:
- (void)viewDidLoad
{
[super viewDidLoad];
UITapGestureRecognizer *tapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(didTapTable)];
[[self tableView] addGestureRecognizer:tapRecognizer];
[tapRecognizer release];
}
- (void)didTapTable
{
[[self tableView] endEditing:YES];
}
Now whenever I tap my table, I end editing. And, as others have said, in textViewDidEndEditing I should be sure to call [textView resignFirstResponder];
[yourTextField resignFirstResponder];
will make the keyboard disappear and editing end.