I'm currently using this UIAlertView to do a login popup,
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Restricted"
message:#"Please Enter Code to Enable Fields"
delegate:self
cancelButtonTitle:#"Cancel"
otherButtonTitles:#"Login"
, nil];
alert.alertViewStyle = UIAlertViewStyleSecureTextInput;
[alert show];
However I would like the text input to be a numeric keyboard instead of the regular keyboard
Is there a easy way to do this, or do I have to look into creating a custom UIAleartView
You can try this to change the keyboard type of the UIAlertView's field:
[[alert textFieldAtIndex:0] setDelegate:self];
[[alert textFieldAtIndex:0] setKeyboardType:UIKeyboardTypeNumberPad];
[[alert textFieldAtIndex:0] becomeFirstResponder];
Cool answer but for iOS 7 I have a little adaptation
alert.alertViewStyle = UIAlertViewStylePlainTextInput;
[alert show];
[[alert textFieldAtIndex:0] setDelegate:self];
[[alert textFieldAtIndex:0] resignFirstResponder];
[[alert textFieldAtIndex:0] setKeyboardType:UIKeyboardTypePhonePad];
[[alert textFieldAtIndex:0] becomeFirstResponder];
UIAlertView *alertView1 = [[UIAlertView alloc] initWithTitle:#"Enter File Number" message:#"" delegate:self cancelButtonTitle:#"Cancel" otherButtonTitles:#"Ok", nil];
alertView1.alertViewStyle = UIKeyboardTypePhonePad;
myTextField = [alertView1 textFieldAtIndex:0];
myTextField.keyboardType=UIKeyboardTypeNumberPad;
[alertView1 setTag:3];
[alertView1 show];
Related
When I have the following code the clickedButtonAtIndex delegate method is called:
UIAlertView * alertTextField = [[UIAlertView alloc] initWithTitle:#"Post To Facebook" message:#"What would you like the post to say?" delegate:self cancelButtonTitle:#"Cancel" otherButtonTitles:#"Continue", nil];
alertTextField.tag = 2;
[alertTextField show];
But when i add in the UIAlertViewStylePlainTextInput in the delegate method is not called.
UIAlertView * alertTextField = [[UIAlertView alloc] initWithTitle:#"Post To Facebook" message:#"What would you like the post to say?" delegate:self cancelButtonTitle:#"Cancel" otherButtonTitles:#"Continue", nil];
[alertTextField setAlertViewStyle:UIAlertViewStylePlainTextInput];
alertTextField.tag = 2;
[alertTextField show];
Why is this?
ensure that you added <UIAlertViewDelegate> in your view controller and your forget to add alertTextField.delegate = self; Then implement the delegate to receive the event.
UIAlertView * alertTextField = [[UIAlertView alloc] initWithTitle:#"Post To Facebook" message:#"What would you like the post to say?" delegate:self cancelButtonTitle:#"Cancel" otherButtonTitles:#"Continue", nil];
[alertTextField setAlertViewStyle:UIAlertViewStylePlainTextInput];
alertTextField.delegate = self; // you forget to add this line
alertTextField.tag = 2;
[alertTextField show];
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
if (buttonIndex == 0) {
NSString *test = [[alertView textFieldAtIndex:0] text];
}
}
UIAlertView no longer available/support in iOS 8 and above so in this place use UIAlertViewController, example for how to use UIAlertViewController see this tutorial
Can we programmatically insert text in UIAlertView's textfield, iOS7
Created UIAlertView with textinput in IOS7.
Can anyone help me with "inserting text programatically in textfield"?
Hopefully this will give answer for your question.
UIAlertView *alertView = [[UIAlertView alloc] init];
alertView.delegate = self;
alertView.title = #"Enter Info";
alertView.alertViewStyle = UIAlertViewStylePlainTextInput;
[alertView addButtonWithTitle:#"Cancel"];
[alertView addButtonWithTitle:#"OK"];
[alertView textFieldAtIndex:0].text = #"My Text";
[alertView show];
You can achieve this by using this code
UIAlertView *alert=[[UIAlertView alloc]initWithTitle:#"" message:#"whatever you like" delegate:self cancelButtonTitle:#"Ok" otherButtonTitles:#"Cancel", nil];
alert.alertViewStyle=UIAlertViewStylePlainTextInput;
[alert textFieldAtIndex:0].text=#"Hello";
[alert show];
and result will be like this:
Please try to use like this..
UIAlertView* av = [[UIAlertView alloc] init];
[av setDelegate:self];
[av setTitle:#"Hi"];
[av setMessage:nil];
[av addButtonWithTitle:#"Cancel"];
[av addButtonWithTitle:#"OK"];
av.alertViewStyle = UIAlertViewStylePlainTextInput;
[av textFieldAtIndex:0].text = #"Text";
You can use text property to set text inside textfield.
textFiled.text = #"YOUR TEXT";
When i pull the tableView downwards, an alertView should appear with a login text field.
The alert has to come but the textField is not to be selected.
Once i click on this textField, then the keyboard should appear.
For this i am using this code:
- (void)toggleCells:(UIRefreshControl*)refreshControl
{
message = [[UIAlertView alloc] initWithTitle:#"Create a new list"
message:#""
delegate:self
cancelButtonTitle:#"Cancel"
otherButtonTitles:#"OK", nil];
[message setAlertViewStyle:UIAlertViewStylePlainTextInput];
[message setTag:1001];
//[message textFieldAtIndex:0].delegate = self;
[refreshControl beginRefreshing];
[message show];
[refreshControl endRefreshing];
//...
}
try: (not so nice but a quick-fix)
message = [[UIAlertView alloc] initWithTitle:#"Create a new list"
message:nil
delegate:self
cancelButtonTitle:#"Cancel"
otherButtonTitles:#"OK", nil];
[message setAlertViewStyle:UIAlertViewStylePlainTextInput];
[message setTag:1001];
[[message textFieldAtIndex:0] setDelegate:self]; //you'll surely need it later
[message show];
[[message textFieldAtIndex:0] resignFirstResponder]; //after showing the alertView
NOTE: The method above ain't really nice.
Alternative Method:
NOTE: declare "BOOL skipAlertTextField;" in the .h
- (void)toggleCells:(UIRefreshControl*)refreshControl {
//...
message = [[UIAlertView alloc] initWithTitle:#"Create a new list"
message:nil
delegate:self
cancelButtonTitle:#"Cancel"
otherButtonTitles:#"OK", nil];
[message setAlertViewStyle:UIAlertViewStylePlainTextInput];
[message setTag:1001];
[[message textFieldAtIndex:0] setDelegate:self];
skipAlertTextField = YES; //important
[message show];
//...
}
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField {
if(textField.tag == 1001 && skipAlertTextField) {
skipAlertTextField = NO;
return NO;
}
return YES;
}
Try this
UIAlertView *av = [[UIAlertView alloc]initWithTitle:#"SayWhat" message:#"Please enter Email address" delegate:self cancelButtonTitle:#"Cancel" otherButtonTitles:#"Ok", nil];
av.alertViewStyle = UIAlertViewStylePlainTextInput;
[av setAlertViewStyle:UIAlertViewStylePlainTextInput];
[[av textFieldAtIndex:0] setPlaceholder:#"Email address"];
[[av textFieldAtIndex:0] setDelegate:self];
[av show];
[[av textFieldAtIndex:0] resignFirstResponder];
Hello to everyone i would like to place my thinking about an alertview. I am thinking to create an Uialertview which will prompt the user to input two integers. Then i would like to retrieve these two integers and put the one on a timer and the second in an sql statement. So if anyone can help on how to implement that i would apreciate it. Thank you all.
Here is my code until now
UIAlertView * alertView = [[UIAlertView alloc] initWithTitle:#"info" message:#"Set time For The Game." delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:#"cancel", nil];
alertView.alertViewStyle=UIAlertViewStylePlainTextInput;
NSLog(#"Entered: %#", [[alertView textFieldAtIndex:0] text]);
[alertView show];
You need to use delegate methods of UIAlterView.
First of all make "self a delegate" instead of nil.
UIAlertView * alertView = [[UIAlertView alloc] initWithTitle:#"info" message:#"Set time For The Game." delegate:self cancelButtonTitle:#"OK" otherButtonTitles:#"cancel", nil];
Than add this function to your class:
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
UITextField *field = [alertView textFieldAtIndex:0];
NSLog(#"%#", field.text);
}
To be 100% correct add also in your header class information that you implement this protocol .
// Try this
UIAlertView * alertView = [[UIAlertView alloc] initWithTitle:#"info" message:#"Set time For The Game." delegate:self cancelButtonTitle:#"OK" otherButtonTitles:#"cancel", nil];
alertView.alertViewStyle=UIAlertViewStylePlainTextInput;
[alertView textFieldAtIndex:0].delegate = self;
[alertView show];
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
NSLog(#"Entered: %#", [[alertView textFieldAtIndex:0]text]);
}
I have UITextField in an UIAlertView.
When I copy and paste 6 characters into the alert view textfield it works fine, but when I paste more than 6 it doesn't work.
How can I solve this?
-(IBAction)btnForgotPasswordHandler:(id)sender{
cancelbtnPressed = NO;
self.alert=[[UIAlertView alloc]initWithTitle:#"Skribbee" message:#"Please input your email address to proceed!" delegate:self cancelButtonTitle:#"OK" otherButtonTitles:#"Cancel", nil];
[self.alert setAlertViewStyle:UIAlertViewStylePlainTextInput];
tfLostPassword=[alert textFieldAtIndex:0];
tfLostPassword.delegate = self;
[tfLostPassword setKeyboardType:UIKeyboardTypeEmailAddress];
[tfLostPassword setPlaceholder:#"Email Address"];
tfLostPassword.returnKeyType = UIReturnKeyGo;
[self.alert show];
}