如何排序NSMutableDictionary

时间:2012-10-10 10:21:31

标签: objective-c ios nsmutabledictionary

我正在使用NSMutableDictionary保存数据并将其加载到UITableview, 这就是字典的样子:

    041517ba8e0542b14e96469d87bba694b42db15a =     (
    "{\n    size             = {360, 480}\n    CGImage.size     = {480, 360}\n    imageOrientation = UIImageOrientationRight\n}",
    041517ba8e0542b14e96469d87bba694b42db15a,
    "2012-10-10 10:17:13 +0000"
);
3582a7ee9ce2e232704c3e51f27bdc9274e965c6 =     (
    "{\n    size             = {360, 480}\n    CGImage.size     = {480, 360}\n    imageOrientation = UIImageOrientationRight\n}",
    3582a7ee9ce2e232704c3e51f27bdc9274e965c6,
    "2012-10-10 10:12:57 +0000",
    "Plastic Cup"
);
3ce8b24a9da8916f2d669f625c9eb28e77b710ec =     (
    "{\n    size             = {360, 480}\n    CGImage.size     = {480, 360}\n    imageOrientation = UIImageOrientationRight\n}",
    3ce8b24a9da8916f2d669f625c9eb28e77b710ec,
    "2012-10-10 10:12:48 +0000",
    Headphones
);
9a2fd3bbd741e52cfc31d2a341ab79241c3048db =     (
    "{\n    size             = {360, 480}\n    CGImage.size     = {480, 360}\n    imageOrientation = UIImageOrientationRight\n}",
    9a2fd3bbd741e52cfc31d2a341ab79241c3048db,
    "2012-10-10 10:11:58 +0000",
    "Men's Wrist Watch"
);
b7b8646cb8548e6c8cc1c83b90b9d8d3b265ed5b =     (
    "{\n    size             = {360, 480}\n    CGImage.size     = {480, 360}\n    imageOrientation = UIImageOrientationRight\n}",
    b7b8646cb8548e6c8cc1c83b90b9d8d3b265ed5b,
    "2012-10-10 10:14:46 +0000",
    Dog
);
c30fe8901a4e14da415981ade707330bda85c2bf =     (
    "{\n    size             = {360, 480}\n    CGImage.size     = {480, 360}\n    imageOrientation = UIImageOrientationRight\n}",
    c30fe8901a4e14da415981ade707330bda85c2bf,
    "2012-10-10 10:14:32 +0000",
    "Dog Olive"
);
d47987a197cc9b383921ef021d5469cd69e02dec =     (
    "{\n    size             = {360, 480}\n    CGImage.size     = {480, 360}\n    imageOrientation = UIImageOrientationRight\n}",
    d47987a197cc9b383921ef021d5469cd69e02dec,
    "2012-10-10 10:12:24 +0000",
    Blurry
);
d8363eb358ce8a6266d9dae37b19628d8be8e604 =     (
    "{\n    size             = {360, 480}\n    CGImage.size     = {480, 360}\n    imageOrientation = UIImageOrientationRight\n}",
    d8363eb358ce8a6266d9dae37b19628d8be8e604,
    "2012-10-10 10:13:08 +0000",
    "Analog Wristwatch"
);
e849e2f6d45a787fff42486cd8cb4d45499b2ef4 =     (
    "{\n    size             = {360, 480}\n    CGImage.size     = {480, 360}\n    imageOrientation = UIImageOrientationRight\n}",
    e849e2f6d45a787fff42486cd8cb4d45499b2ef4,
    "2012-10-10 10:15:14 +0000",
    "Red Sports Car"
);
f0c5598cd2a5314d64bd25dffbef2c98be78ac0f =     (
    "{\n    size             = {360, 480}\n    CGImage.size     = {480, 360}\n    imageOrientation = UIImageOrientationRight\n}",
    f0c5598cd2a5314d64bd25dffbef2c98be78ac0f,
    "2012-10-10 10:12:40 +0000",
    "Laptop Computer Keyboard"
);

它包含照片但不按顺序(添加到词典中)我想要的是按照添加此照片的顺序绘制UITableView

任何想法?

2 个答案:

答案 0 :(得分:2)

字典是未分类的集合。

你应该真正考虑将字典或键只放入数组中。

然后你可以使用数组进行排序,并使用键来引用字典。

答案 1 :(得分:1)

每次将照片添加到词典时,都会使用NSMutableArray键并为NSMutableArray添加一个键。该数组将保持秩序