iOS multiple text fields on a UIAlertview In IOS 7

前端 未结 3 998
名媛妹妹
名媛妹妹 2020-12-10 06:22

So the new iOS 7 has come out and I\'m trying to add multiple textFields and labels to the UIAlertviews. I need three. I\'ve been trying to add them as subviews and that doe

相关标签:
3条回答
  • 2020-12-10 06:59

    If you want to add just two textfields to your UIAlertView, you can use UIAlertViewStyleLoginAndPasswordInput and modify the textfields as follows:

    UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Some Title" message:@"Some Message." delegate:self cancelButtonTitle:@"Okay" otherButtonTitles:@"No, thanks", nil];
    alert.alertViewStyle = UIAlertViewStyleLoginAndPasswordInput;
    [alert textFieldAtIndex:1].secureTextEntry = NO; //Will disable secure text entry for second textfield.
    [alert textFieldAtIndex:0].placeholder = @"First Placeholder"; //Will replace "Username"
    [alert textFieldAtIndex:1].placeholder = @"Second Placeholder"; //Will replace "Password"
    [alert show];
    

    Afterwards, in the UIAlertView delegate, you can simply get the text using:

    text1 = [alert textFieldAtIndex:0].text;
    text2 = [alert textFieldAtIndex:1].text;
    
    0 讨论(0)
  • 2020-12-10 07:19

    You can change accessoryView to any own customContentView in a standard alert view in iOS7

    [alertView setValue:customContentView forKey:@"accessoryView"];
    

    Note that you must call this before [alertView show].

    Simplest illustrating example:

    UIAlertView *av = [[UIAlertView alloc] initWithTitle:@"TEST" message:@"subview" delegate:nil cancelButtonTitle:@"NO" otherButtonTitles:@"YES", nil];
    UIView *v = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 50)];
    v.backgroundColor = [UIColor yellowColor];
    [av setValue:v forKey:@"accessoryView"];
    [av show];
    

    enter image description here

    0 讨论(0)
  • 2020-12-10 07:25

    The only solution i found using UIAlertView with more than one text field in iOS7 is for login only.

    use this line to initialize your alertView

    [alert setAlertViewStyle:UIAlertViewStyleLoginAndPasswordInput];
    

    and this to grab the users input:

    user = [alert textFieldAtIndex:0].text;
    pw = [alert textFieldAtIndex:1].text
    

    For other purposes than login view the other threads like this on: UIAlertView addSubview in iOS7

    0 讨论(0)
提交回复
热议问题