2011-08-10 44 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

请谁有解决方案? –