代码之家  ›  专栏  ›  技术社区  ›  enbr

为UITableView排序JSON字典

  •  3
  • enbr  · 技术社区  · 15 年前

    我正在使用TouchJSON检索我的应用程序的信息并将其放入字典中。我想能够排序的价值观,如难度和评级。我该怎么办?我已经包括了我的.m文件。 谢谢,恩伯 http://pastie.org/1091334

    1 回复  |  直到 15 年前
        1
  •  3
  •   William Niu    15 年前

    你可以用 NSSortDescriptor 对具有指定键的字典数组进行排序。因此,例如,以下内容可以按每个字典中的键“ratings”对数组进行排序:

    NSSortDescriptor *ratingsSortDescriptor = [[[NSSortDescriptor alloc] initWithKey:@"ratings" ascending:YES] autorelease];
    rows = [rows sortedArrayUsingDescriptors:[NSArray arrayWithObject:ratingsSortDescriptor]];