有没有办法重复数组中NSDictionaries的数量? [英] Is there a way to duplicate the number of NSDictionaries in an array?

查看:59
本文介绍了有没有办法重复数组中NSDictionaries的数量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前在表视图中有这个 NSDictionary s数组,但是当表视图向下滚动时,我需要复制该数组中的字典数。有没有办法实现这一目标,并且还指定或知道词典名称是什么?

I currently have this array of NSDictionarys in my table view, but I need to duplicate the number of dictionaries in the array as the table view scrolls down. Is there a way to achieve this, and also specify or know what the dictionary names will be?

NSMutableDictionary *d0 = [[NSMutableDictionary alloc] init];

NSMutableDictionary *d1 = [[NSMutableDictionary alloc] init];

NSMutableDictionary *d2 = [[NSMutableDictionary alloc] init];

NSMutableDictionary *d3 = [[NSMutableDictionary alloc] init];

NSMutableDictionary *d4 = [[NSMutableDictionary alloc] init];


objects = [NSMutableArray arrayWithObjects:d0, d1, d2, d3, d4, nil];


推荐答案

首先,它的接缝易于创建循环中的字典:

First of all, it seams to be easier to create the dictionaries in a loop:

NSMutableArray *objects = [NSMutableArray new];
for( int i = 0; i < 5; i++ )
{
   [objects addObject:[NSMutableDictionary new]];
}

如果您要复制字典,可以使用循环也是如此:

If you want to "duplicate" the dictionaries, you can do that with a loop, too:

for( NSMutableDictionary *dictionary in [objects copy])
{
  [objects addObject:[dictionary mutableCopy]];
}

但是我无法摆脱这种感觉,即您的整体方法是错误的。其背后的想法是什么?

But I cannot get rid of the feeling that your whole approach is wrong. What is the idea behind that?

这篇关于有没有办法重复数组中NSDictionaries的数量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆