2011-08-10 68 views
0

請問爲什麼我無法比較我的textfiled tovalue?haw比較UITextFiled和NSString

所有的
-(void)testPass:(id)sender 
{ 
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
    NSString *documentsDirectory = [paths objectAtIndex:0]; 
    NSString *path = [documentsDirectory stringByAppendingPathComponent:@"Info.plist"]; 
    NSDictionary *dict = [[NSDictionary alloc] initWithContentsOfFile:path]; 

    NSString *value; 
    value = [dict valueForKey:@"Password"]; 





    if ([value isEqualToString:password.text]) { 

     res = [[XMLTestViewController alloc] initWithNibName:@"XMLTestViewController" bundle:nil]; 
     res.modalTransitionStyle = UIModalTransitionStyleCoverVertical; 
     [self.view addSubview:res.view]; 
    } 
    else { 


     UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"IAA" 
                 message:@"Wrong Password" delegate:self cancelButtonTitle:@"Cancel" 
               otherButtonTitles:@"OK", nil]; 


     [alert show]; 
     [alert release]; 
    } 

} 
+0

沒有朋友有想法????? –

回答

0

首先,你應該使用NSDictionaryobjectForKey:而不是KVC的valueForKey:訪問字典的內容。

二,你確定你的password.text返回正確的值嗎?

+0

是的,它返回正確的值,我使用NSDictionary *詞典 –

+0

幫我請我沒有解決方案 –

0
-(void)testPass:(id)sender 
    { 
     NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
     NSString *documentsDirectory = [paths objectAtIndex:0]; 
     NSString *path = [documentsDirectory stringByAppendingPathComponent:@"Info.plist"]; 
     NSDictionary *dict = [[NSDictionary alloc] initWithContentsOfFile:path]; 

     NSString *value; 
     value = [dict valueForKey:@"Password"]; 

    //to test the values in console 
    NSLog(@"Value; %@", value); 
    NSLog(@"PWordText: %@", password.text); 



     if ([value isEqualToString:password.text]) { 

      res = [[XMLTestViewController alloc] initWithNibName:@"XMLTestViewController" bundle:nil]; 
      res.modalTransitionStyle = UIModalTransitionStyleCoverVertical; 
      [self.view addSubview:res.view]; 
     } 
     else { 


      UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"IAA" 
                  message:@"Wrong Password" delegate:self cancelButtonTitle:@"Cancel" 
                otherButtonTitles:@"OK", nil]; 


      [alert show]; 
      [alert release]; 
     } 

} 

在這之後檢查控制檯是否打印了值。

+0

2011-08-10 11:05:42.887 XMLTest [55877:207]價值; pol 2011-08-10 11:05:42.887 XMLTest [55877:207] PWordText:pol –

+0

是的corse即時通訊現在聊天 –

+0

請誰有解決方案? –