为什么每当我向NSMutableArray添加一个新对象NSMutableDictionay时它会替换我之前的对象?
例如:
[appDelegate.tracksDict setObject:currentTrackTitle forKey:@"track_title"];
[appDelegate.tracksDict setObject:currentTrackTopic forKey:@"topic"];
[appDelegate.tracksArray addObject:[appDelegate.tracksDict copy]];
它的印刷......
2010-10-01 14:03:35.021 XML[48889:207]Tracks Array: {
topic = "Cold Calling";
"track_title" = "Sleeping and selling";
}
2010-10-01 14:03:35.021 XML[48889:207]Tracks Array: {
topic = "Gate Keeper";
"track_title" = "Selling like a chicken";
}
2010-10-01 14:03:35.021 XML[48889:207]Tracks Array: {
topic = "Gate Keeper";
"track_title" = "Don't you try to sell";
}
而不是...... ...
2010-10-01 14:03:35.021 XML[48889:207]Tracks Array: {
topic = "Cold Calling";
track_title = "Sleeping and selling";
topic = "Gate Keeper";
track_title = "Selling like a chicken";
topic = "Gate Keeper";
track_title = "Selling like a chicken";
}
我确信这是愚蠢的,因为我不太熟悉这种语言。
答案 0 :(得分:1)
根据您发布的“打印”,您的问题难以理解,但听起来您需要NSArray的NSDictionary对象。 NSDictionary只能为给定的密钥保存单个对象,但可以拥有(几乎)无限密钥。看起来你需要的是构建一个字典数组,每个轨道一个。