我目前在表视图中有这个NSDictionary
数组,但是当表视图向下滚动时,我需要复制数组中的字典数。有没有办法实现这一点,还指定或知道字典名称是什么?
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];
答案 0 :(得分:2)
首先,它更容易在循环中创建字典:
NSMutableArray *objects = [NSMutableArray new];
for( int i = 0; i < 5; i++ )
{
[objects addObject:[NSMutableDictionary new]];
}
如果你想&#34;重复&#34;字典,你也可以用循环来做到这一点:
for( NSMutableDictionary *dictionary in [objects copy])
{
[objects addObject:[dictionary mutableCopy]];
}
但我无法摆脱整个方法错误的感觉。这背后的想法是什么?