1

您好我正在使用下面的代码,其中包括包含 UserID 和 Password 字段的 alertView。

这些 UserID 和 Password 是文本字段,我将密码字段设置为安全的,但是当我稍后想要访问在密码字段中输入的数据时,它在密码字段中显示没有值..

我的代码是

    self.loginPassword = [[ UIAlertView alloc] initWithTitle:@"Please Login" message:@"Enter Valid UserID and Password\n\n\n\n" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:@"Cancel", nil];
    //[self.loginPassword setAlertViewStyle:UIAlertViewStyleLoginAndPasswordInput];

    self.userIDText = [[UITextField alloc] initWithFrame:CGRectMake(12.0, 80.0, 260.0, 25.0)];
    self.userIDText.text=@"";
    [self.userIDText setBackgroundColor:[UIColor whiteColor]];
    [self.userIDText setKeyboardAppearance:UIKeyboardAppearanceAlert];
    [self.userIDText setAutocorrectionType:UITextAutocorrectionTypeNo];
    [self.userIDText setTextAlignment:UITextAlignmentLeft];

    self.passwordField = [[UITextField alloc] initWithFrame:CGRectMake(12.0,115.0, 260.0, 25.0)];
    self.passwordField.text=@"";
    [self.passwordField setBackgroundColor:[UIColor whiteColor]];
    [self.passwordField setKeyboardAppearance:UIKeyboardAppearanceAlert];
    [self.passwordField setAutocorrectionType:UITextAutocorrectionTypeNo];
    [self.passwordField setTextAlignment:UITextAlignmentLeft];

    [self.loginPassword addSubview:self.userIDText];
    [self.loginPassword addSubview:self.passwordField];
    self.passwordField.secureTextEntry = YES;
    [self.loginPassword setTag:2];
    [self.loginPassword show];
    [self.loginPassword release];

请给我一些解决方案..

4

2 回答 2

2

创建和内置UIAlertView

UIAlertView *alert = [[UIAlertView alloc] init];
// Define Alertview Type to Login&Password
[alert setAlertViewStyle:UIAlertViewStyleLoginAndPasswordInput];
// Set Delegate to access Input Value
[alert setDelegate:self];
// show it
[alert show];

Delegate在你interface(.h 文件)中设置在你的(.m 文件)UIAlertViewDelegate 中实现这个委托方法implementation

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    // Access your Username & Password from alertview and store them for further use.
    NSString *username = [[alertView textFieldAtIndex:0] text];
    NSString *password = [[alertView textFieldAtIndex:1] text];

    NSLog(@"Username : %@ , Password : %@",username, password);
}
于 2013-04-22T03:58:09.427 回答
1

这可能会对您有所帮助。只需看一下代码。

https://github.com/josecastillo/EGOTextFieldAlertView

于 2013-04-22T04:01:22.967 回答