0

我正在尝试使用来自 NSDictionary 的数据填充我的 UITable 视图。如果我能够使用 indexPath 来访问数据,那就太好了cellForRowAtIndexPath

{
"December 2012" =     (
    "2012-12-08 13:56:53 +0000"
);
"July 2013" =     (
    "2013-07-17 12:54:22 +0000"
);
"June 2013" =     (
    "2013-06-17 12:29:57 +0000",
    "2013-06-20 12:02:17 +0000",
    "2013-06-21 11:55:58 +0000",
    "2013-06-21 12:16:59 +0000",
    "2013-06-25 12:59:39 +0000",
    "2013-06-25 13:01:10 +0000",
    "2013-06-25 13:02:22 +0000",
    "2013-06-26 12:24:28 +0000",
    "2013-06-27 12:29:00 +0000"
);
"May 2013" =     (
    "2013-05-23 12:54:35 +0000"
);

}

2013-06-28 08:49:49.948 [4714:c07] <NSIndexPath 0x747b840> 2 indexes [0, 0]
2013-06-28 08:49:49.950 [4714:c07] <NSIndexPath 0x8563750> 2 indexes [1, 0]
2013-06-28 08:49:49.951 [4714:c07] <NSIndexPath 0x747e740> 2 indexes [2, 0]
2013-06-28 08:49:49.95  [4714:c07] <NSIndexPath 0x7473880> 2 indexes [2, 1]
2013-06-28 08:49:49.953 [4714:c07] <NSIndexPath 0x747a5d0> 2 indexes [2, 2]
2013-06-28 08:49:49.954 [4714:c07] <NSIndexPath 0x7489550> 2 indexes [2, 3]
2013-06-28 08:49:49.955 [4714:c07] <NSIndexPath 0x818ddc0> 2 indexes [2, 4]
2013-06-28 08:50:10.298 [4714:c07] <NSIndexPath 0x955f6c0> 2 indexes [2, 5]
2013-06-28 08:50:10.330 [4714:c07] <NSIndexPath 0x8360750> 2 indexes [2, 6]
2013-06-28 08:50:10.346 [4714:c07] <NSIndexPath 0x85739e0> 2 indexes [2, 7]
2013-06-28 08:50:10.363 [4714:c07] <NSIndexPath 0x9560690> 2 indexes [2, 8]
2013-06-28 08:50:10.380 [4714:c07] <NSIndexPath 0x9065b00> 2 indexes [3, 0]
2013-06-28 08:50:10.998 [4714:c07] <NSIndexPath 0x9660f70> 2 indexes [2, 2]

上面你会看到我的字典的布局,下面是相应的索引路径。获取数据的最佳方法是什么?我应该使用 NSDictionary 以外的东西吗?

4

3 回答 3

3

从字典 ( allKeys) 中获取键,对它们进行排序并存储它们。每当字典更改时,更新您的排序键数组。当您获得索引路径时,使用它来获取适当的键,然后您就可以访问字典。

于 2013-06-28T12:58:49.133 回答
3

就像@wain 和@pgd 所说的那样。取一个可变数组,然后添加从字典中获得的每个数组。

例如:

  displayArray = [[NSMutableArray alloc]init]; // 

  NSArray *keys = [MyDict allKeys];  // Getting all key from you dictionary

  for (id key in MyDict) {
    NSArray *anArray = [dict objectForKey:key];

    [displayArray addObject:anArray]
}

在显示使用节号来获取数组时。

   NSArray * array = [displayArray  objectAtIndex:indexPath.section]

希望这会有所帮助。

于 2013-06-28T13:25:55.943 回答
2

An NSArrayof NSArrays 将更适合使用 an 访问NSIndexPath。除此之外,@Wait 的解决方案也应该有效。

于 2013-06-28T13:00:17.483 回答