NSDictionary读plist文件顺序问题
来源:互联网 发布:深圳网络统考英语 编辑:程序博客网 时间:2024/05/21 11:12
怎么我的字典这么杂乱无章?原来字典本来就是无序的,杂凑的。
NSDictionary读plist文件顺序问题
Filed Under (iPad) by CouldHll on 14-02-2011
Tagged Under : iOS, iPad
问题描述:
这些天在做AD,NSDictionar读取出来的顺序不是plist文件中的顺序。
问题分析:
试了各种库和方法,无效,网上搜了一些不算解决办法的方法 。
问题解决:
(1) Keep an array of keys along with the dictionary. Then loop through the array and use the keys to get the values. (You’ll have to add your own checks to keep the same key from appearing in the array twice.)
1,简单说来就是,把nsdictionary的所有key组成的nsarray按自己的要求排序,然后根据这个key组成的array来获取对应的value的array。key的array不要扔掉,每次要按顺序获取值的时候都需要它。
(2)You could keep an array of custom objects, one custom object for each pair (give the object .key and .value properites) . That’s a very object-oriented way, but you lose the ability to easily find the value for a key (you have to loop through the array.)
2,不直接用nsdictionary,而是用一个nsarray,里面每个object都是一个只有一对key-value的nsdictionary。这个方法的缺点是,找某个value或者key会变得很麻烦,需要遍历。
(3)You could keep two arrays of strings, one for keys and one for values.
to find a value for a key, you just use
keyIndex = [myKeys indexOfObject: keyIWant];
keyValue = [myValues objectAtIndex: keyIndex];
3,不用nsdictionary,而是用两个对应的nsarray。相互调用,分别做key和value。
- NSDictionary读plist文件顺序问题
- NSDictionary 读写 plist 文件
- NSDictionary转plist文件本地读与写
- 向info.plist文件中写入数据(nsdictionary)
- Data from NSDictionary plist
- NSDictionary+plist简单示例
- NSDictionary+plist简单示例 .
- iOS - plist文件写入问题:
- C++读plist文件
- iOS用plist初使化NSDictionary
- 在iOS开发中调用本地plist文件并封装为NSDictionary字典类型
- plist文件
- plist文件
- plist文件
- Plist文件
- plist文件
- plist 文件
- Plist文件
- android音乐播放器_专辑下歌曲列表
- DTD详解
- Qt4.8下应用OpenCV2.4.4搭建环境详细步骤(win7系统)
- C#自带Json序列化工具使用
- linux 技巧:使用 screen 管理你的远程会话
- NSDictionary读plist文件顺序问题
- 计算10000以下所有相亲数之和。
- html 表格
- int溢出的问题
- 关于 flex 的资料
- GTK 安装与测试
- ArrayList和LinkedList的操作性能对比
- OpenERP 7.0成倍提高并发处理能力
- u-boot中nandflash初始化流程分析(转)