我在UITextfields
中有三个UIAlertView
,同时点击一个UITextfield
并尝试点击其他不选择并创建问题,也就是辞职第一响应者的问题,是吗在UITextfield
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];
}
答案 0 :(得分: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];
}
答案 1 :(得分: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];
希望这些信息有所帮助。谢谢。