This question already has answers here:
UIAlertView's textfield does not show keyboard in iOS8
(8 answers)
Closed 8 years ago.
I have a UIAlertView with a textfield inside (UIAlertViewStylePlainTextInput) that automatically pops up a keyboard in iOS 7. However, when I upgraded to iOS 8, the keyboard didn't automatically popup and instead I would have to tap on the textfield to get the keyboard to popup. Is there anyway to restore that automatic keyboard popup to the UIAlertView textfield when I call it?
UIAlertView * alert = [[UIAlertView alloc] initWithTitle:#"" message:#"The amount?" delegate:self cancelButtonTitle:#"Cancel" otherButtonTitles:#"Ok", nil];
alert.alertViewStyle = UIAlertViewStylePlainTextInput;
UITextField * alertTextField = [alert textFieldAtIndex:0];
alertTextField.keyboardType = UIKeyboardTypeNumberPad;
[alertTextField setTextAlignment:NSTextAlignmentCenter];
[alert show];
[alert release];
Update: [alertTextField becomeFirstResponder]; does not work nor does
[[alert textFieldAtIndex:0] setDelegate:self];
[[alert textFieldAtIndex:0] becomeFirstResponder];
Also, there is a textfield flashing indicator inside the textview, which is problematic because there is no actual keyboard that pops up automatically until the user taps on the textfield itself.
I had to unselect "Connect Hardware Keyboard" in the iOS Simulator Hardware->Keyboard menu options for running in iOS 8.
If you add this line just after [alert show] it will make the keyboard pop up.
[alertTextField becomeFirstResponder];
Hope this helps
Related
I am running iOS8 and I am showing a UIAlertView, like this
UIAlertView * alert = [[UIAlertView alloc] initWithTitle:#"Test" message:#"Please enter number" delegate:self cancelButtonTitle:#"Enter" otherButtonTitles:nil];
alert.alertViewStyle = UIAlertViewStylePlainTextInput;
[[alert textFieldAtIndex:0] setKeyboardType:UIKeyboardTypeNumberPad];
[[alert textFieldAtIndex:0] becomeFirstResponder];
[alert show];
And then when the enter is tapped I have
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
NSLog(#"Entered: %#",[[alertView textFieldAtIndex:0] text]);
}
And when enter is tapped the method is called an I see the number and the UIAlertView goes away but the keyboard lags for about 1 second or 2. How can I make is so that the keyboard doesn't lag, I tried calling
[self resignFirstResponder];
from with in the clickedButtonAtIndex method but it didn't change anything.
Thanks for the help.
You are telling the view controller (self) to resignFirstResponder but it's actually the text field that it the first responder, so do this:
[[alertView textFieldAtIndex:0] resignFirstResponder];
The UIAlertView message doesn't show properly when the text field in it is being edited (when the keyboard is being displayed). Here's how it looks like:
When the keyboard isn't there:
This is the code that creates the alert view:
UIAlertView *alertView = [[UIAlertView alloc]
initWithTitle:#"Title"
message:#"Enter a name for your recipe"
delegate:self
cancelButtonTitle:#"Cancel"
otherButtonTitles:#"OK", nil];
[alertView setAlertViewStyle:UIAlertViewStylePlainTextInput];
[alertView show];
Is there a way to change the size of some components of the view so that it fits properly in the screen when the keyboard is displayed?
Edit: I just discovered that the alert view becomes scrollable when the keyboard appears. So if you scroll down, you can see the message. But I didn't notice that the first time the alert view popped up, and other users might not either. For now, I'm using what Visput suggested.
It is standard behavior for iOS. You could see the same layout in "Photos" application when create new Album in landscape mode.
I think the best way in this situation: place all text to message but title set to nil.
In your case:
UIAlertView *alertView = [[UIAlertView alloc]
initWithTitle:nil
message:#"Title: Enter a name for your recipe"
delegate:self
cancelButtonTitle:#"Cancel"
otherButtonTitles:#"OK", nil];
I need some kind of easy way to be able to edit a title when a button is pressed. I would basically just redirect to a view controller with the edit possibility included but that just seems to "heavy". It would be far better to just be able to edit text in a pop up box or something. Is this possible and if so how would I do this?
You can use an UIAlertview control to update your title.
In your button click put the following code.For example
-(IBAction)ButtonClick:(id)sender{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Title" message:#"Message" delegate:self cancelButtonTitle:#"Done" otherButtonTitles:nil];
alert.alertViewStyle = UIAlertViewStylePlainTextInput;
[alert show];
[alert release];
}
In the UIAlertViewDelegate method
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
if(buttonIndex == alertView.cancelButtonIndex)
NSLog(#"%#", [alertView textFieldAtIndex:0].text);
}
I hope this will help you.
Please note the alert.alertViewStyle = UIAlertViewStylePlainTextInput only works in iOS 5.0 and later.
alert = [[UIAlertView alloc] initWithTitle:#"Enter Student Name" message:#"" delegate:self cancelButtonTitle:#"Cancel" otherButtonTitles:#"Save", #"Save and Add", nil];
alert.tag = 1;
alert.alertViewStyle=UIAlertViewStylePlainTextInput;
[alert show];
its been working beautifully in potrait mode but in landscape my UITextfield going out of screen.and now i want to move a alertView frame a little bit down so that it will be visible .
Unfortunately you can't change any thing in the UIAlertView design in iOS7, you should use it as is, you have three chices here:
Take off the cancel button (If i were you i would do this).
Use a custom UIAlertView from cocoacontrols.com and put the three buttons at the same line.
Use another control like popover or modal.
I just found a strange problem, when I try to use three buttons in an UIAlertView, the view is displayed weirdly, as you can see in this screenshot :
Here is the code :
UIAlertView *alert=[[UIAlertView alloc]initWithTitle:#"Login" message:nil delegate:self cancelButtonTitle:#"Cancel" otherButtonTitles:#"Login",#"Forget Password", nil];
[alert setAlertViewStyle:UIAlertViewStyleLoginAndPasswordInput];
UITextField *place=[alert textFieldAtIndex:0];
place.placeholder=#"Email";
[alert show];
[alert release];
Please suggest me how I can correct this. Thanks.