如何将字典值升序设置为UITableview

时间:2016-01-15 18:43:10

标签: ios objective-c json uitableview

我在json之下。当我设置为UITableview但json没有设置为升序

在我的tableview标题中设置字典键ex。级别1,级别2,级别3

我想要Level1,Level2,Level3但我在tableview标题中得到Level2,Level1,Level3

    {
            Level1 =         (
                            {
                    "value" = 10000;
                    "image" = “image01.png”;
                    "name" = Luck;
                    "id" = 11;
                }
            );
            “Level2” =         (
                            {
                    "image" = "image02.png";
                    "name" = "Invites 3";
                    "id" = 5;
                },
                            {
                    "image" = "image03.png";
                    "name" = "Best coin”;
                    "id" = 2;
                }
            );
            Level3 =         (
                            {
                    "value" = 1000;
                    "image" = "image04.png";
                    "name" = “get clock“;
                    "id" = 3;
                },
                            {
                    "value" = 1500;
                    "image" = "image05.png";
                   "name" = “slot”;
                    "id" = 4;
                },
                            {
                    "value" = 1500;
                    "image" = "image06.png";

                    "name" = “Friend List”;
                    "id" = 5;
                },
                            {
                    "value" = 2500;
                    "image" = "image07.png";

                    "name" = "Deals";
                    "id" = 7;
                },
                            {
                    "value" = 15000;
                    "image" = "image08.png";
                    "name" = “time all”;
                    "id" = 10;
                }, 
}

2 个答案:

答案 0 :(得分:2)

字典按定义无序排列。

你可以

  • 获得" Level"键(作为数组)
  • 排序。
  • 按排序键的顺序获取值。

答案 1 :(得分:2)

简短的回答是:不要使用字典作为表视图的数据源,因为字典本质上是无序的。

@Jarmod提供的链接向您展示了如何通过构建排序的键数组来实现此功能,但更好的答案是将数据重构为字典数组。