访问Plist文件数组中的字符串值? [英] Accessing Strings Values within Plist file Arrays?

查看:126
本文介绍了访问Plist文件数组中的字符串值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的项目中有一个Plist文件,其中包含许多不同的数组.每个数组是一个不同的类别,然后包含针对单个问题的其他数组.我遇到的问题是访问这些数组中的节点及其值.

I've got a Plist file in my project that has a number of different arrays; each array is a different category which then contains additional arrays for individual questions. The problem I'm having is accessing the nodes and their values within these arrays.

我正在使用的代码:

-(IBAction)nextleft {

    if (questionCounter > 1) {
        questionCounter -= 1;
    }

    [self nextQuestion];

}

-(IBAction)nextright {

    if (questionCounter < 20) {
        questionCounter += 1;
    }

    [self nextQuestion];

}

-(void)nextQuestion {

    NSArray *pair;

    pair = [categories objectAtIndex:questionCounter]; 

    plistQuestion = [pair objectAtIndex:0];
    plistAnswer = [pair objectAtIndex:1];

    abbreviation.text = plistQuestion;

}

我的类别数组从我的Plist文件中填充这一行;

categories = [NSArray arrayWithContentsOfFile:@"questions.plist"];

推荐答案

您可以创建一个类,在该类中,您有两个NSString实例(问题和答案),其中包含问题&的值.答案.创建一个由该类对象组成的类别数组.

You can create a class in which you have two instances of NSString (question & answer) which consist the value of question & answer.Create an array of category which consist of object of that class.

这篇关于访问Plist文件数组中的字符串值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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