您好我正在使用以下代码,其中包含包含UserID和密码字段的alertView。
这些UserID和密码是文本字段,我将密码字段设置为安全,但是当我以后想要访问在密码字段中输入的数据时,它在密码字段中显示没有值。
我的代码是
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];
请建议我一些解决方案..
答案 0 :(得分: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
(.h文件)interface
中设置UIAlertViewDelegate
在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);
}
答案 1 :(得分:1)
这可能会对你有所帮助。只需看看代码。