English 中文(简体)
加入职业道德规范
原标题:Adding an Entry to a NSDictionary doesn t work

我提出以下问题。 我想在一位理论家增加4个条目,这是xl驱动的。 因此,Xml档案中有4个条目。 我在Xml parser使用以下代码添加所有条目:

    - (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName
  namespaceURI:(NSString *)namespaceURI
 qualifiedName:(NSString *)qName{ 
    if ([elementName isEqualToString:@"Placemark"]) {
        NSString *batsen = [placemarkData objectForKey:@"name"];
        [Placemarks setObject:placemarkData forKey:batsen];
        NSLog(@"adding story: %@", batsen);
    }
}

问题在于,它像他凌驾于商标上的条目。 如果我读到原木档案,我只看上去。 之所以如此奇怪,是因为记录(介绍故事)确实显示4个标识信息。

I use the following code to read out the Placemark dictionary:

NSEnumerator *enumerator = [appDelegate.Placemarks keyEnumerator];
id key;

while ((key = [enumerator nextObject])) {

    /* code that uses the returned key */
    NSString *theElement = key;
    NSLog(@"Element: %@", theElement);
} 

是否有任何建议? 预支款项

问题回答

当你确定安全等级表现有钥匙的价值时,以前的价值即予以公布:

If aKey already exists in the dictionary, 
the dictionary’s previous value object for that key is sent a release message 
and anObject takes its place.

rel=“nofollow”>c.f on NSMutableDictionary in Rainbow/a>

就你而言,你的词典钥匙应绘制成一个阵列(NSMutableArray),以便你储存一个指4×ml元素的钥匙。

NSMutableDictionary is required to add items to a dictionary. 该法典采用国家统一法,简化新的、扩大的可变性NSDictionary:

// Make an immutable dictionary by combining 2 dictionaries (new entries are added, old entries are updated)
+ (NSDictionary *)dictionaryFromDictionary:(NSDictionary *)original WithAddedEntries:(NSDictionary *)entriesToAdd
{
    NSMutableDictionary *final = [NSMutableDictionary dictionaryWithDictionary:original];
    [final addEntriesFromDictionary:entriesToAdd];
    // Done
    return [NSDictionary dictionaryWithDictionary:final];
}




相关问题
List Contents of Directory in a UITableView

I am trying to list the contents of Ringtones directory in a TableView, however, I am only getting the last file in the directory in ALL cells, instead of file per cell. This is my code: - (...

iPhone NSUserDefaults persistance difficulty

In my app i have a bunch of data i store in the NSUserdefaults. This information consists of an NSObject (Object1) with NSStrings and NSNumbers and also 2 instances of yet another object (Object2). ...

Writing a masked image to disk as a PNG file

Basically I m downloading images off of a webserver and then caching them to the disk, but before I do so I want to mask them. I m using the masking code everyone seems to point at which can be found ...

Resize UIImage with aspect ratio?

I m using this code to resize an image on the iPhone: CGRect screenRect = CGRectMake(0, 0, 320.0, 480.0); UIGraphicsBeginImageContext(screenRect.size); [value drawInRect:screenRect blendMode:...

Allowing interaction with a UIView under another UIView

Is there a simple way of allowing interaction with a button in a UIView that lies under another UIView - where there are no actual objects from the top UIView on top of the button? For instance, ...

热门标签