gpt4 book ai didi

iphone - 如何从 Label 中的 pList 中获取数据

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:17:11 25 4
gpt4 key购买 nike

我有一个 RegistrationController 屏幕来存储 email-id ,password,DOB,Height WeightlogininController 屏幕将 email-idpassword 匹配到登录目的。

现在,在某些third 屏幕中,我只需要从已登录用户的 plist 中获取 HeightWeight 即可显示它在标签上。现在如果我将 email-idpassword 的值存储在 LoginViewController 的字符串中,并在新屏幕中调用它匹配如果匹配则给出 Height,Weight ..如果它正确那么如何从中获取 Height,Weight同一个的plist。

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

这是我的代码:

-(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 属性..请参阅下面的整个示例..

更新:

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"];

}

希望这对你有帮助...

关于iphone - 如何从 Label 中的 pList 中获取数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13950903/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com