Youaregreat
Youaregreat

Reputation: 69

UitextFields in UIAlertView selecting iOS

I have three UITextfields in UIAlertView, while tap on one UITextfield and try to tap on other its not selecting and creating a problem, also problem of resigning first responder, is it not good choice of using UITextfield in UIAlertView

- (IBAction)heightMethod:(id)sender
{
    self.centimeterTextField = [[UITextField alloc] initWithFrame:CGRectMake(12.0, 45.0, 260.0, 25.0)];
    centimeterTextField.placeholder = @"  Centimeters";
    self.centimeterTextField.delegate=self;
    self.centimeterTextField.tag=3;

   [ self.centimeterTextField setBackgroundColor:[UIColor whiteColor]];

   [self.alertHeight addSubview: self.centimeterTextField];

    self.ptextfield = [[UITextField alloc] initWithFrame:CGRectMake(40, 80.0, 80, 25.0)]; ptextfield.placeholder = @"   Feet";

    self.ptextfield.delegate=self;

    self.ptextfield.tag=4;

    [self.ptextfield setBackgroundColor:[UIColor whiteColor]];
    [self.alertHeight addSubview:self.ptextfield];
    self.ptextfieldInches = [[UITextField alloc] initWithFrame:CGRectMake(140, 80.0, 80, 25.0)]; ptextfieldInches.placeholder = @"   Inches";
    self.ptextfieldInches.delegate=self;
    self.ptextfieldInches.tag=5;

  [ptextfieldInches setBackgroundColor:[UIColor whiteColor]];

    [self.alertHeight addSubview:ptextfieldInches];

   [self.centimeterTextField setKeyboardType:UIKeyboardTypeDecimalPad];

    [self.ptextfieldInches setKeyboardType:UIKeyboardTypeDecimalPad];

    [self.ptextfield setKeyboardType:UIKeyboardTypeDecimalPad];

     self.alertHeight.tag=1;

   [self.alertHeight show];  
}

Upvotes: 0

Views: 1087

Answers (2)

Jig Patel
Jig Patel

Reputation: 82

- (void) presentSheet {
UIAlertView *alert = [[UIAlertView alloc]initWithTitle: @"Enter Information"
message:@"Specify the Name and URL" delegate:self cancelButtonTitle:@"Cancel"otherButtonTitles:@"OK", nil];

[alert addTextFieldWithValue:@"" label:@"Enter Name"]; 
[alert addTextFieldWithValue:@"http://" label:@"Enter URL"];

UITextField *tf = [alert textFieldAtIndex:0];
 tf.clearButtonMode = UITextFieldViewModeWhileEditing;
 tf.keyboardType = UIKeyboardTypeAlphabet; 
 tf.keyboardAppearance = UIKeyboardAppearanceAlert;

 tf.autocapitalizationType = UITextAutocapitalizationTypeWords;
 tf.autocorrectionType = UITextAutocorrectionTypeNo;
// URL field
 tf = [alert textFieldAtIndex:1];
tf.clearButtonMode = UITextFieldViewModeWhileEditing; tf.keyboardType =  UIKeyboardTypeURL;
tf.keyboardAppearance = UIKeyboardAppearanceAlert; tf.autocapitalizationType =  UITextAutocapitalizationTypeNone; tf.autocorrectionType = UITextAutocorrectionTypeNo;
[alert show]; 
} 

Upvotes: 3

Dhruvik
Dhruvik

Reputation: 982

You can now create a UIAlertView with a style.

UIAlertView now has a property - alertViewStyle that you can set to one of the enum values

1. UIAlertViewStyleDefault

2. UIAlertViewStyleSecureTextInput

3. UIAlertViewStylePlainTextInput

4. UIAlertViewStyleLoginAndPasswordInput

Once you've created the alert view, you set it style and display it. After dismissing the alert, you can access the contents of the fields using the textFieldAtIndex property of the alert view.

or else you can use this one also.,

IAlertView* dialog = [[UIAlertView alloc] init];
[dialog setDelegate:self];
[dialog setTitle:@"Enter Name"];
[dialog setMessage:@" "];
[dialog addButtonWithTitle:@"Cancel"];
[dialog addButtonWithTitle:@"OK"];

UITextField *nameField = [[UITextField alloc] initWithFrame:CGRectMake(20.0, 45.0, 245.0, 25.0)];
[nameField setBackgroundColor:[UIColor whiteColor]];
[dialog addSubview:nameField];
CGAffineTransform moveUp = CGAffineTransformMakeTranslation(0.0, 70.0);
[dialog setTransform: moveUp];
[dialog show];
[dialog release];
[nameField release];

Hope this information helps. Thank you.

Upvotes: 0

Related Questions