In my iPad application, there is an alertview of following style UIAlertViewStylePlainTextInput. The problem is I'm unable to enter any other language characters(å,ß,Ω) in alertview textfield. It's simply showing blank string in textfield after entering other language character.
saveAlert = [[UIAlertView alloc] initWithTitle:#"Please provide a name for your design." message:nil delegate:self cancelButtonTitle:nil otherButtonTitles:#"OK",#"Cancel",nil];
[saveAlert setTag:SAVE_HTML_NAME_ALERT_TAG];
[saveAlert setAlertViewStyle:UIAlertViewStylePlainTextInput];
[saveAlert show];
alertTextField = [saveAlert textFieldAtIndex:0];
alertTextField.font = [UIFont fontWithName:#"Arial" size:15.0f];
[alertTextField setTag:SAVE_ALERT_TEXT_FIELD_TAG];
[alertTextField setDelegate:self];
Other normal textfields are working fine in application, properly displaying other language characters. There's only problem with alertview's textfield.
Related
In my iOS app, I create a UIAlert and add a UITextView to it dynamically:
UIAlertView *tweetAlert = [[UIAlertView alloc] initWithTitle:#"Compose Tweet"
message:nil
delegate:self
cancelButtonTitle:#"Cancel"
otherButtonTitles:nil];
tweetTextView = [UITextView new];
[tweetTextView setText:[NSString stringWithFormat:#"%# %#", [[NSUserDefaults standardUserDefaults] valueForKey:#"tweetText"], self.setShareURL]];
[tweetAlert setValue:tweetTextView forKey:#"accessoryView"];
[tweetAlert addButtonWithTitle:#"Tweet"];
[tweetAlert show];
[tweetTextView becomeFirstResponder]; // focus textview and open keyboard
I attempt to focus on the UITextView in the last line so that the keyboard is open when the UIAlertView appears. However, the keyboard does not appear, and the UITextView is not in focus.
I also tried
[[tweetAlert valueForKey:#"accessoryView"] becomeFirstResponder];
But I get the error
*** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<UIAlertView 0x1358b3200> valueForUndefinedKey:]: this class is not key value coding-compliant for the key accessoryView.'
Any idea how to focus on the dynamically created UITextView, which is embedded as an accessoryView in a UIAlertView?
You can use the UIAlertViewDelegate method - (void)didPresentAlertView:(UIAlertView *)alertView to make the textview become first responder.
- (void)didPresentAlertView:(UIAlertView *)alertView {
[tweetTextView becomeFirstResponder];
}
It is generally not recommended that you modify the view hierarchy of alert views. You should just use a text entry UIAlertView:
UIAlertView *tweetAlert = [[UIAlertView alloc] initWithTitle:#"Compose Tweet"
message:nil
delegate:self
cancelButtonTitle:#"Cancel"
otherButtonTitles:nil];
tweetAlert.alertViewStyle = UIAlertViewStylePlainTextInput;
In IOS 7 the method I'm using has plenty of room for both the login and the password input, however when jumping to IOS 8, the textfields seems to have grown leaving the textfield in the UIAlertView Cut off. Here is a picture of what Should be happening, and below that is what is happening in IOS 8.
So how do i return them to normal size so it all fits in the alert view?
here is my code
UIAlertView *av = [[UIAlertView alloc]
initWithTitle:#"Add Job"
message:#"Set a job name and wage below"
delegate:self
cancelButtonTitle:#"Cancel"
otherButtonTitles:#"Add", nil];
[av setAlertViewStyle:UIAlertViewStyleLoginAndPasswordInput];
// Alert style customization
[[av textFieldAtIndex:1] setSecureTextEntry:NO];
[[av textFieldAtIndex:0] setPlaceholder:#"Job Name"];
[[av textFieldAtIndex:1] setPlaceholder:#"Wage"];
[[av textFieldAtIndex:1] setKeyboardType:UIKeyboardTypeDecimalPad];
[av show];
The issue no longer exists using Xcode 6 beta 2
How do I specify that my keyboard for the UIAlertView text field is to be a number pad keyboard? I am setting alertViewStyle to UIAlertViewStylePlainTextInput.
I think you can do something like:
UITextField* tf = [alertView textFieldAtIndex:0];
tf.keyboardType = UIKeyboardTypeNumberPad;
See the UIAlertView and UITextInputTraits docs
Please refer the code below:
UIAlertView *progressAlertView = [[UIAlertView alloc]
initWithTitle:#"Title"
message:#"Message"
delegate:self
cancelButtonTitle:#"Cancel"
otherButtonTitles:nil];
progressAlertView.message=#"Hello, I am the new one";
Voice over always reads "Message" and never reads the new message string set in the second line "Hello, I am the new one". There's no way to change this accessibility label of the bodyTextLabel control/subView of UIAlertView.
Any idea how to make UIAlertView change its accessibility labels after its alloc'ed?
Thanks,
-Shilpi
You can use accessibilityTraits as UIAccessibilityTraitUpdatesFrequently to read updated message.
it works like:
alertObj.accessibilityTraits = UIAccessibilityTraitUpdatesFrequently;
Thanks
use this way for set message of UIAlertView
UIAlertView *progressAlertView = [[UIAlertView alloc]
initWithTitle:#"Title"
message:#"Message"
delegate:self
cancelButtonTitle:#"Cancel"
otherButtonTitles:nil];
[alertView setMessage:#"Hello, I am the new one"];
[alertView show];
For More About UIAlertView Refer this
http://developer.apple.com/library/ios/#documentation/uikit/reference/UIAlertView_Class/UIAlertView/UIAlertView.html
You can change the subviews of UIAlertView to change single attributes like the accessibility label:
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Test"
message:#"Message"
delegate:nil
cancelButtonTitle:#"Ok"
otherButtonTitles:nil];
// In a standard UIAlertView there are 2 UILabels and some buttons
// The UILabel with the message is always the 2nd object in the array
NSArray *subviews = alert.subviews;
UILabel *messageLabel = [subviews objectAtIndex:1];
[messageLabel setAccessibilityLabel:#"Some other text"];
With this code you only change the accessibility label, so that VoiceOver reads another text but the old text is shown.
In your case you should set the accessibility label to the same as you want to set the message of the UIAlertView.
When the user opens my app, I want to check for a value stored in the defaults, and if it is not present prompt the user to input a value. The storing/reading of the value appears to be working.
-(void) viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
NSLog(#"Checking if there is an email address set");
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSString * emailAddress = [defaults objectForKey:#"emailAddress"];
if (IsEmpty(emailAddress))
{
NSLog(#"email address is blank, prompting user to enter one..");
self.emailPromptAlert = [[UIAlertView alloc] initWithTitle:#"Alert"
message:#"Enter Email address:"
delegate:self
cancelButtonTitle:#"Cancel"
otherButtonTitles:#"OK", nil];
[self.emailPromptAlert setAlertViewStyle:UIAlertViewStylePlainTextInput];
[self.emailPromptAlert setTag:1];
[self.emailPromptAlert show];
}
}
The problem that I have, is when I do a clean install of my app and load for the first time, the alert shows up as expected but there is no keyboard shown, so the user can't actually type anything.
Clicking the home button then bringing the app back into the foreground again, the same alert is on screen but this time the keyboard is actually showing.
What can I do to make sure the keyboard gets shown the first time?
That's a weird behavior, Why don't you try showing the alert in the next runloop
[self.emailPromptAlert performSelector:#selector(show) withObject:nil afterDelay:0];
I had the same problem. In my case, the keyboard was already visible at the time that I showed the alert. I resolved it by dismissing the keyboard before showing the alert:
[myTextField resignFirstResponder];
[myAlert show];
I am not totally sure, but maybe this could work?
self.emailPromptAlert = [[UIAlertView alloc] initWithTitle:#"Alert"
message:#"Enter Email address:"
delegate:self
cancelButtonTitle:#"Cancel"
otherButtonTitles:#"OK", nil];
[self.emailPromptAlert setAlertViewStyle:UIAlertViewStylePlainTextInput];
[self.emailPromptAlert setTag:1];
[self.emailPromptAlert show];
//try this?
UITextField *textField = [self.emailPromptAlert textFieldAtIndex:0];
[textField becomeFirstResponder];
This doesn't really get to the root of the problem of why it isn't showing in the first place, but it could be a solution.