0

我想将 icdcodeDictionary 添加到 backlist 中,但它会更改 backlist 的所有元素。在此过程之后,它们与最后添加的项目相同。我该如何解决这个问题?我跟着这个链接。http://iphonedevsdk.com/forum/iphone-sdk-development/88286-adding-object-to-nsmutablearray-changes-all-objects.html 但什么也没发生。谢谢。

NSMutableDictionary *icdcodeDictionary;
@property (nonatomic, retain) NSMutableArray *backlist;
[self.backlist addObject:icdcodeDictionary];

的结果

NSLog(@"backlist %d 索引: %@",self.backlist.count-2,[icdcodeDictionary objectForKey:@"Name"]);

NSLog(@"backlist %d index: %@",self.backlist.count-1,[icdcodeDictionary objectForKey:@"Name"]):

backlist 0 index: Urlar
backlist 1 index: Urlar

但我想要这个:

backlist 0 index: Neoplazma
backlist 1 index: Urlar
4

2 回答 2

1

这与您正在打印的字典相同。您需要为每个addObject:.

[self.backlist addObject:[NSMutableDictionary dictionaryWithDictionary:icdcodeDictionary]];
于 2013-11-07T13:09:34.120 回答
0

好的,当您在 forloop 中设置字典时,我遇到了您的问题,您需要在 for 循环中编写如下代码。

// here it is for loop
 for (i=0; i<2; i++)
 {
 // this dictinary needs to call how many times   
 you set object
  NSMutableDictionary * mut= 
 [NSMutableDictionary dictionary];
 // now set your object inside dictionary
 }
于 2013-11-07T13:08:31.403 回答