<i id='sZ2Wt'><tr id='sZ2Wt'><dt id='sZ2Wt'><q id='sZ2Wt'><span id='sZ2Wt'><b id='sZ2Wt'><form id='sZ2Wt'><ins id='sZ2Wt'></ins><ul id='sZ2Wt'></ul><sub id='sZ2Wt'></sub></form><legend id='sZ2Wt'></legend><bdo id='sZ2Wt'><pre id='sZ2Wt'><center id='sZ2Wt'></center></pre></bdo></b><th id='sZ2Wt'></th></span></q></dt></tr></i><div id='sZ2Wt'><tfoot id='sZ2Wt'></tfoot><dl id='sZ2Wt'><fieldset id='sZ2Wt'></fieldset></dl></div>
    <bdo id='sZ2Wt'></bdo><ul id='sZ2Wt'></ul>

      <small id='sZ2Wt'></small><noframes id='sZ2Wt'>

    1. <legend id='sZ2Wt'><style id='sZ2Wt'><dir id='sZ2Wt'><q id='sZ2Wt'></q></dir></style></legend>
    2. <tfoot id='sZ2Wt'></tfoot>
    3. 从 PList 读取字典时的错误顺序

      False order when reading Dictionary from PList(从 PList 读取字典时的错误顺序)

      <i id='KrYYa'><tr id='KrYYa'><dt id='KrYYa'><q id='KrYYa'><span id='KrYYa'><b id='KrYYa'><form id='KrYYa'><ins id='KrYYa'></ins><ul id='KrYYa'></ul><sub id='KrYYa'></sub></form><legend id='KrYYa'></legend><bdo id='KrYYa'><pre id='KrYYa'><center id='KrYYa'></center></pre></bdo></b><th id='KrYYa'></th></span></q></dt></tr></i><div id='KrYYa'><tfoot id='KrYYa'></tfoot><dl id='KrYYa'><fieldset id='KrYYa'></fieldset></dl></div>
    4. <legend id='KrYYa'><style id='KrYYa'><dir id='KrYYa'><q id='KrYYa'></q></dir></style></legend><tfoot id='KrYYa'></tfoot>

      <small id='KrYYa'></small><noframes id='KrYYa'>

      • <bdo id='KrYYa'></bdo><ul id='KrYYa'></ul>
          <tbody id='KrYYa'></tbody>

              • 本文介绍了从 PList 读取字典时的错误顺序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                I have a plist from which i am trying to access its animations in sequence (as defined in the PList) but when I store it in NSDictionary and then try to play animation one by one it is not playing them in sequence. e.g,

                int index = 0;
                [self playAnimation:[animTypes objectAtIndex:index++]];
                [self playAnimation:[animTypes objectAtIndex:index++]];
                

                This is the code of my Plist:

                <plist version="1.0">
                <dict>
                <key>Boy</key>
                    <dict>
                    <key>Enter</key>
                    <dict>
                        <key>disabled</key>
                        <false/>
                        <key>halfCycle</key>
                        <true/>
                        <key>fps</key>
                        <integer>1</integer>
                        <key>defaultFrame</key>
                        <integer>0</integer>
                        <key>useZwoptex</key>
                        <true/>
                        <key>frames</key>
                        <array>
                            <string>boy-000.png</string>
                        </array>
                    </dict>
                    <key>Jump</key>
                    <dict>
                        <key>disabled</key>
                        <false/>
                        <key>halfCycle</key>
                        <true/>
                        <key>fps</key>
                        <integer>13</integer>
                        <key>defaultFrame</key>
                        <integer>0</integer>
                        <key>useZwoptex</key>
                        <true/>
                        <key>frames</key>
                        <array>
                            <string>boyjump-000.png</string>
                            <string>boyjump-001.png</string>
                            <string>boyjump-002.png</string>
                        </array>
                    </dict>
                    <key>Turnaround</key>
                    <dict>
                        <key>disabled</key>
                        <false/>
                        <key>halfCycle</key>
                        <true/>
                        <key>fps</key>
                        <integer>21</integer>
                        <key>defaultFrame</key>
                        <integer>0</integer>
                        <key>useZwoptex</key>
                        <true/>
                        <key>frames</key>
                        <array>
                            <string>boyturnaround-000.png</string>
                            <string>boyturnaround-001.png</string>
                            <string>boyturnaround-002.png</string>
                        </array>
                    </dict>
                </dict>
                </plist>
                


                Plz guide me how to load the animations in sequence?

                解决方案

                Yes, djhworld is correct - NSDictionary objects don't return entries in the order they're created.

                I'm fairly new to Objective C and came up against the very same problem. The solution I cooked up allowed me to still use a single NSDictionary, but before using it I sort the entries based on the key. In a util class, I sort the keys and return a sorted array:

                +(NSArray *) sortedKeysForDictionary:(NSDictionary *)dict {
                    NSArray *keys = [dict allKeys];
                    NSMutableArray *anArray = [NSMutableArray arrayWithArray:keys];
                    keys = [anArray sortedArrayUsingSelector:@selector(localizedCompare:)]; 
                    return keys;
                }
                

                Then I just run through the keys pulling them from the Dictionary in order...

                -(void) processEntries {
                    NSArray *keys = [Utils sortedKeysForDictionary:myDictionary];
                    for (int i=0; i<keys.count; i++){
                        NSString *key = [keys objectAtIndex:i];
                        id dictEntry = [myDictionary valueForKey:key];
                
                        // process the entry here
                
                    }
                
                }
                

                The only caveat is that you have to use keys that sort properly. I've adopted a convention of using keys in the form nnn:keyName, so I can sort them but still provide human-readable names. e.g. 001:process XYZ.

                这篇关于从 PList 读取字典时的错误顺序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                Hardware Volume buttons change in app volume(硬件音量按钮更改应用程序音量)
                Cocos2d - How to check for Intersection between objects in different layers(Cocos2d - 如何检查不同层中对象之间的交集)
                Highlight Read-Along Text (in a storybook type app for iPhone)(突出显示朗读文本(在 iPhone 的故事书类型应用程序中))
                Cocos2D + Disabling only Retina iPad Graphics(Cocos2D + 仅禁用 Retina iPad 图形)
                Proper cocos2d scene restart?(正确的 cocos2d 场景重启?)
                [ios.cocos2d+box2d]how to disable auto-rotation?([ios.cocos2d+box2d]如何禁用自动旋转?)
                  • <bdo id='wFvXS'></bdo><ul id='wFvXS'></ul>
                    <legend id='wFvXS'><style id='wFvXS'><dir id='wFvXS'><q id='wFvXS'></q></dir></style></legend>
                      <tbody id='wFvXS'></tbody>

                    <tfoot id='wFvXS'></tfoot>

                      1. <i id='wFvXS'><tr id='wFvXS'><dt id='wFvXS'><q id='wFvXS'><span id='wFvXS'><b id='wFvXS'><form id='wFvXS'><ins id='wFvXS'></ins><ul id='wFvXS'></ul><sub id='wFvXS'></sub></form><legend id='wFvXS'></legend><bdo id='wFvXS'><pre id='wFvXS'><center id='wFvXS'></center></pre></bdo></b><th id='wFvXS'></th></span></q></dt></tr></i><div id='wFvXS'><tfoot id='wFvXS'></tfoot><dl id='wFvXS'><fieldset id='wFvXS'></fieldset></dl></div>

                        <small id='wFvXS'></small><noframes id='wFvXS'>