Objective c 为什么不';难道我字典里的孩子们都填饱了吗
大家好,我正在使用NSXMLParser解析一些xml数据。 我正在使用这些数据构建一个树表示,以创建drilldowntable的层次结构Objective c 为什么不';难道我字典里的孩子们都填饱了吗,objective-c,nsdictionary,Objective C,Nsdictionary,大家好,我正在使用NSXMLParser解析一些xml数据。 我正在使用这些数据构建一个树表示,以创建drilldowntable的层次结构 - (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qualifiedName attributes:(NSDicti
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName
namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qualifiedName
attributes:(NSDictionary *)attributeDict {
if([elementName isEqualToString:@"exercises"]) {
//init tree
appDelegate.Tree = [NSMutableDictionary new];
appDelegate.Rows = [NSMutableArray new];
[appDelegate.Tree setObject:appDelegate.Rows forKey:@"Rows"];
...
现在,如果正在读取xml中的元素menuitem,那么它将初始化并将子元素添加到菜单项字典中
if([elementName isEqualToString:@"menuitem"]) {
appDelegate.theChildren = [NSMutableArray new];
[appDelegate.menu_item setObject:appDelegate.theChildren forKey:@"Children"];
这一切都按计划进行
然而,以下不是我想要的方式。
当我看到另一个标签(锻炼mob)时,我希望孩子们被填满,这只发生在字典底部的项目上
有人知道为什么它不至少填充我的两个项目吗?我的意思是,它将子数组添加到这两个项目中,所以为什么只填充底部的一个。如果在xml代码中添加另一个xmlline,如下所示:
<menu_mob>
<menuitem id="1" text="Press this for exercises" pic="workout" />
<menuitem id="2" text="VirtuaGym online" pic="online" />
*<menuitem id="3" text="the Added Line" pic="online" />*
</menu_mob>
**
然后,它会将所有子项添加到底部菜单项(想象另一个字典项(3))。
那为什么呢?嗯,我好像在重置阵列;)所以问题解决了
<menu_mob>
<menuitem id="1" text="Press this for exercises" pic="workout" />
<menuitem id="2" text="VirtuaGym online" pic="online" />
*<menuitem id="3" text="the Added Line" pic="online" />*
</menu_mob>