如何从Label中的pList获取数据 [英] How to fetch data from pList in Label

查看:86
本文介绍了如何从Label中的pList获取数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有 RegistrationController 屏幕存储 email-id 密码 DOB 高度重量 logininController 用于匹配 email-id 密码的屏幕以进行记录 - 目的。

I have a RegistrationController screen to store email-id ,password,DOB,Height,Weight and logininController screen to match email-id and password to log-in purpose.

现在,在某些第三个屏幕中,我只需要获取登录用户的plist中的高度权重将其显示在label.now上如果我存储<$ c $的值c> email-id 和密码进入 LoginViewController in string并在其中调用如果匹配则匹配的新屏幕然后给出高度权重 ..如果它更正了如何获取高度权重来自同一个人的plist。

Now, In some third screen I have to fetch only the Height,Weight from the plist of the logged-in user to display it on the label.now if I Store the values of email-id and password in from LoginViewController in string and call it in the new screen to match if matches then gives Height,Weight ..if it corrects then how to fetch Height,Weight from the plist of the same one.

如何从字符串中存储的plist中获取?

How can I fetch from the stored plist in a string?

这是我的代码:

-(NSArray*)readFromPlist
 {
   NSArray *documentPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
  NSUserDomainMask, YES); 
  NSString *documentsDirectory = [documentPaths objectAtIndex:0];
 NSString *documentPlistPath = [documentsDirectory stringByAppendingPathComponent:@"XYZ.plist"];

   NSDictionary *dict = [NSDictionary dictionaryWithContentsOfFile:documentPlistPath];

   NSArray *valueArray = [dict objectForKey:@"title"];

   return valueArray;

 }



- (void)authenticateCredentials {
    NSMutableArray *plistArray = [NSMutableArray arrayWithArray:[self readFromPlist]];

    for (int i = 0; i< [plistArray count]; i++)
    {
        id object = [plistArray objectAtIndex:i];

        if ([object isKindOfClass:[NSDictionary class]]) {
            NSDictionary *objDict = (NSDictionary *)object;

            if ([[objDict objectForKey:@"pass"] isEqualToString:emailTextFeild.text] && [[objDict objectForKey:@"title"] isEqualToString:passwordTextFeild.text])
            {
                NSLog(@"Correct credentials");
                return;
            }
            NSLog(@"INCorrect credentials");
        } else {
             NSLog(@"Error! Not a dictionary");
        }
    }
}


推荐答案

首先从你的plist文件中获取整个值,然后将 NSArray 存储到 NSMutableArray 中并获取值它的 objectAtIndex valueForKey property..see完整的例子如下..

First get whole value from your plist file after that store this NSArray into NSMutableArray and get the value with its objectAtIndex and valueForKey property..see whole example bellow..

更新:

NSString* plistPath = [[NSBundle mainBundle] pathForResource:@"yourFileName" ofType:@"plist"];
NSArray *contentArray = [NSArray arrayWithContentsOfFile:plistPath];
NSMutableArray *yourArray = [[NSMutableArray alloc] initWithArray:contentArray];

    for (int i = 0; i< [yourArray count]; i++)
    {
        id object = [yourArray objectAtIndex:i];

        if ([object isKindOfClass:[NSDictionary class]]) {
            NSDictionary *objDict = (NSDictionary *)object;

           yourLableWeight.text = [[objDict objectForKey:@"Weight"];// set index with your requirement
         yourLableHeight.text = [[objDict objectForKey:@"Height"];

    }

希望这有助于你......

hope this help you...

这篇关于如何从Label中的pList获取数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆