开发者

haw compare UITextFiled and NSString

please why i cant compare my textfiled tovalue?

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

}


First of all, you should use NSDictionary's objectForKey: instead of KVC's valueForKey: to access dictionary contents.

Second, are you sure your password.text returns right value?


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

}

After this check the console for value printed there.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜