0

我有三个UITextfieldsin UIAlertView,同时点击一个UITextfield并尝试点击另一个它没有选择和创建问题,还有辞职第一响应者的问题,使用UITextfieldin不是很好的选择吗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];  
}
4

2 回答 2

3
- (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]; 
} 
于 2013-04-02T05:25:54.523 回答
0

您现在可以创建带有样式的 UIAlertView。

UIAlertView 现在有一个属性 - alertViewStyle,您可以将其设置为枚举值之一

1. UIAlertViewStyleDefault

2. UIAlertViewStyleSecureTextInput

3. UIAlertViewStylePlainTextInput

4. UIAlertViewStyleLoginAndPasswordInput

创建警报视图后,您可以设置它的样式并显示它。解除警报后,您可以使用警报视图的 textFieldAtIndex 属性访问字段的内容。

否则你也可以使用这个。,

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];

希望这些信息有所帮助。谢谢你。

于 2013-04-02T05:17:15.460 回答