【问题标题】:how to access the secureTextEntry for further use?如何访问secureTextEntry以供进一步使用?
【发布时间】:2013-04-22 03:38:12
【问题描述】:

您好,我正在使用以下代码,其中包含包含用户 ID 和密码字段的 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];

请给我一些解决方案..

【问题讨论】:

  • 为什么要创建自己的文本字段而不是使用UIAlertViewStyleLoginAndPasswordInput 的样式?
  • 没有 iOS 4.3 将不支持这个.. 我正在创建 subView 到 alertView

标签: iphone ios objective-c ios5 ios4


【解决方案1】:

创建和内置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];

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

- (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);
}

【讨论】:

  • 我知道这个解决方案..正如它在我的代码中所评论的那样..但这在 iOS4.3 中不受支持..所以我使用了上面的甲酸..
  • 它在 IOS 5.0 中受支持,但你需要做一些我对我的代码所做的事情,你可以像我在示例中所做的那样访问 textField 值
  • 我以前用过这个甲酸盐.. 但要求是 iOS 4.3.. 所以我不能用这个..
  • 你已经完成了正确的编码,你可以像以前一样在 alertview 中添加文本字段,但是要访问值,你必须像我在委托方法中那样使用我的代码
  • 谢谢您的回答,但此链接更有帮助:“github.com/josecastillo/EGOTextFieldAlertView”正如 RJR 所建议的那样......
【解决方案2】:

这可能对你有帮助。看看代码。

https://github.com/josecastillo/EGOTextFieldAlertView

【讨论】:

    猜你喜欢
    • 2019-07-29
    • 2011-03-01
    • 1970-01-01
    • 2017-08-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-03-17
    相关资源
    最近更新 更多