ios - UITableView 中的 NSDictionary - 使用索引路径

标签 ios objective-c uitableview nsdictionary

我正在尝试使用 NSDictionary 中的数据填充我的 UITable View 。如果我能够像 cellForRowAtIndexPath 中给出的那样使用 indexPath 访问数据,那就太好了。

{
"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 以外的东西吗?

最佳答案

就像@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]

希望这会有所帮助。

关于ios - UITableView 中的 NSDictionary - 使用索引路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17365258/

相关文章:

ios - 分离约束和 UI 元素(UIView、UIButton、UITextField 等)声明以分离 swift 文件

objective-c - UITextView 顶部有奇怪的边距?

iphone - 限制要显示的表格单元格数量

ios - 如何删除tableView单元iOS

ios - 如何检测滑动手势方向?

ios - 按下 uiview 会使灰色背景 swift 出现

ios - 设置默认时区不成功

iOS。将 block 作为参数传递给 block

ios - 快速错误 self 。在 super.init() 调用之前使用

ios - 在 UiNavigationBar 上禁用多点触摸