2013-04-22 39 views
1

嗨我正在使用下面的代碼,其中包括alertView包含用戶名和密碼字段。如何訪問secureTextEntry以供進一步使用?

這些用戶ID和口令文本字段,我做密碼字段作爲安全的,但是當我以後要訪問密碼字段中輸入的數據,其顯示密碼字段沒有值..

我的代碼是

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)]; 
    [email protected]""; 
    [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)]; 
    [email protected]""; 
    [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]; 

請建議我一些解決方案..

+1

你爲什麼要創建自己的文本字段,而不是使用'UIAlertViewStyleLoginAndPasswordInput'的風格? – rmaddy 2013-04-22 03:43:15

+0

沒有iOS 4.3不會支持這..我創建子視圖alertView – Raju 2013-04-22 03:45:41

回答

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

設置你Delegateinterface(h文件)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); 
} 
+0

我知道這個解決方案..作爲它的評論我的代碼..但這不支持iOS4.3 ..所以我用上面的甲酸。 – Raju 2013-04-22 04:05:46

+0

它支持在IOS 5.0中,但你需要做一些我用我的代碼做的事情,你可以像我在例子中那樣訪問textField Value – 2013-04-22 04:08:49

+0

我以前用過這個formate,但是需求是iOS 4.3 ..所以我不能使用這個.. – Raju 2013-04-22 04:17:53

相關問題