I have a UITextField that the user enters their name into. When they tap a button, my app checks to make sure that they actually entered something. If they didn't I have an alert view come up stating so, and then below that I have this code:
[textField becomeFirstResponder];
The only problem is, when the user hits the ok button on the alert view, the text field does not become selected so that the user can enter text into it, instead they have to tap it manually, which defeats the purpose of the code. It's like the alert view is preventing this from happening. What do you suggest I do? Thanks for your help!
How do you show your alert? Do you call [textField becomeFirstResponder] right after the [alert show] ?
If so, that's the problem. You should register your controller as your alert's delegate, then call becomeFirstResponder when you receive the alertView:didDismissWithButtonIndex: message.
Take a look at the UIAlertViewDelegate protocol.
Related
In my app, sometimes all the textfield 's copy&paste menu is missing when the user is tapping in the textfield.
But when the user kill the app and restart again, the function comes back.
Has anyone encountered this problem before?
I do not subclass UITextField, what could cause such problem?
Any advice would be greatly appreciated.
Thank you.
I have found that in on of my view controller, I used two alertViews. After the first alertView diss, I immediately pop up the second UIAlertView in the callback
- (void) alertView:(UIAlertView *) alertView clickedButtonAtIndexL(NSInteger) buttonIndex
{
//[thesecondalertview show];
}
Since the firstAlert view does not completely dimiss, pop up the second alertview it may cause the UIWindow disorder.
If we pop up the second UIAlertView in the first alertviews's callback,
- (void) alertview:(UIAlertView*)alertview didDissmissWithButtonIndex:(NSInteger) buttonIndex
the problem solved.
For some reason, resignFirstResponder is not working. I am not sure why? I have tried to call it from textFieldDidEndEditing and nothing happens. A NIB is being used and each's delegate is pointing to files owner.
What needs to be done to get the keyboard to dismiss?
Thanks.
Don't use -textFieldDidEndEditing. That's called after the text field resigns firstResponder status, which is what you're trying to use it as a hook to make happen. Cart before horse, chicken-and-egg kind of problem.
Instead use -textFieldShouldReturn to get triggered when the return key is pressed (and remember to return YES; from that.) Also float a clear custom button behind the elements of the view and handle a "background tap" that goes through all the text fields on your view and resigns first responder on the lot of them.
actually you should return NO so that the text field does not begin editing at all. If it does, the firstresponder gets set and the keyboard pops up again.
Make sure your setting your delegates for the textfield.
myTextField.delegTe = self;
And you are using in your header:
<UITextFieldDelegate>
EDIT:
Try:
if(textField == myTextField){
[textField resignFirstResponder];
}
I have a form that looks like the following (see image). If the user hits the Login button, I want the keypad to disappear. How do I do that.
Note that TextFieldDelegate methods wouldnt get called since the user is simply hitting the UIButton (Login). Hence, anything I can put in the IBAction for this button?
Normally the keyboard should be dismissed automatically when the user taps somewhere outside of the textfield, but you can also manually hide it using
[textField resignFirstResponder]
set delegate for your text field <UITextFieldDelegate>
and over ride this method
-(BOOL)textFieldShouldReturn:(UITextField *)textField
{
[textField resignFirstResponder];
return YES;
}
I fill information then tap "Done" button for doing some process and show loading view for waiting.
I need loading view is over every view, but How can I do?
Thanks for adviser.
Here is my image (I'm new in here, so I can't post image)
http://www.freeimagehosting.net/image.php?62e2584aea.png
You should make your keyboard disappear from the screen as soon as user taps on done button.
call this method
[myTextField resignFirstResponder]
when you start loading
this is the best answer for your question
[textField setInputAccessoryView:inputAccessoryView];
Did you observe the UIKeyboardWillShowNotification and UIKeyboardDidShowNotification notifications? You can update the view elements in the handlers.
Try to add the loading HUDView ro whatever you are using for the purpose on the application's keywindow.
as
[[UIApplication sharedApplication].keyWindow addSubview:loadingView];
ALso resigning the responder while the loadingview is displayed is really a very important thing you should do.
[myTextField resignFirstResponder]
The UIAlertViewDelegate protocol defines two methods, alertView:clickedButtonAtIndex: and alertView:didDismissWithButtonIndex:, which seem to me to be identical in usefulness.
Why is there a clickedButtonAtIndex and a didDismissButtonWithIndex when they both do the same thing? I realize there is also a willDismissButtonWithIndex that happens before the alert view is dismissed, but is there any reason to use clickedButtonAtIndex instead of didDismissButtonWithIndex?
I found a more useful difference between the two:
When showing a UIAlertView, and the device goes to sleep, alertView:didDismissWithButtonAtIndex: gets called, even though the alert view is not actually dismissed. It is shown again once the device wakes up. alertView:clickedButtonAtIndex: is only called when the user clicks one of the buttons.
The alertView:clickedButtonAtIndex: is called when the user clicks a button on an alert view whereas the alertView:didDismissWithButtonIndex: is called after an alert view is dismissed from the screen. (See the UIAlertViewDelegate Protocol Reference.)
The difference is minimal but it allows you to do something before or after animation.
If the alert view disappears for any reason (including being covered by another UIAlertView, going to sleep, etc.), didDismissWithButtonAtIndex: is called. This can mean that the method can be called even without the user clicking on anything. This can lead to unexpected behaviour if you depend on this delegate callback to be called in response to the user actually clicking on a button. In this case clickedButtonAtIndex: is more useful.
I couldn't reproduce Ed's behaviour by locking my device with the alert view present on iOS 7.
However, the most important difference between alertView:clickedButtonAtIndex:, alertView:didDismissWithButtonIndex: and alertView:willDismissWithButtonIndex: is that the first method (clickedButtonAtIndex:) is only called when the user explicitly taps on a button on your alert view (hence 'clicked').
Is it possible that an alert view is dismissed without clicking on a button? Yes, you could programmatically hide an alert view using the UIAlertView method dismissWithClickedButtonIndex:animated:.
So, if you need some behavior to be always triggered upon the dismissal of the alert view—whether it was triggered by the user tapping on a button or triggered programmatically—then using the didDismissWithButtonIndex: and willDismissWithButtonIndex: makes more sense.