0

每当我向我的 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";
}

我敢肯定这是愚蠢的,因为我不太懂这种语言。

4

1 回答 1

1

根据您发布的“打印”,您的问题很难理解,但听起来您想要一个 NSDictionary 对象的 NSArray。NSDictionary 只能为给定键保存一个对象,但可以拥有(实际上)无限的键。看起来您需要的是构建一组字典,每首曲目一个。

于 2010-10-01T18:58:28.967 回答