как сравнить UITextFiled и NSString - PullRequest
       3

как сравнить UITextFiled и NSString

0 голосов
/ 10 августа 2011

пожалуйста, почему я не могу сравнить мое текстовое значение?

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

}

Ответы [ 2 ]

0 голосов
/ 10 августа 2011
-(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 голосов
/ 10 августа 2011

Прежде всего, вы должны использовать NSDictionary objectForKey: вместо valueForKey: KVC для доступа к содержимому словаря.

Во-вторых, вы уверены, что password.text возвращает правильное значение?

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...