2013-04-02 33 views
0

我有三个UITextfieldsUIAlertView,而水龙头上一个UITextfield并尝试挖掘其他的没有选择,创造出了问题,也辞职第一响应的问题,是它使用UITextfield不是好选择UIAlertViewUitextFields在UIAlertView中选择iOS的

- (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

,粘贴代码 –

+0

是的,请张贴代码在这里 – Prashant

+0

使用标签的正确textfild及其委托检查与巫Textfild呼吁。或者可能会忘记给三个TextFiled之一的代表进行正确检查。 –

回答

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

其不工作,没有声明addTextFieldWithValue显示。 – Youaregreat

+0

@Youaregreat我建议参考iPhone Developer's Cookbook第9页。没有115 –

+0

@ouaregreat这不是我开发的这段代码是从iPhone开发人员的食谱,这是ios初学者真的很好的来源。我个人每天都会提及它。 –

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

希望这个信息帮助。谢谢。

+0

其良好的,但对我来说它不够的,因为我已经为米添加了三个文本字段,并转换成了字,并且在赋值的同时显示所有的值,我继续。 – Youaregreat