创建一个动态UITableView

时间:2011-04-22 15:16:51

标签: iphone xml arrays xcode

您好StackOverflow的所有朋友,我面临另一个问题,我会尝试与您解决。假设我有这个XML,它的字段每次都会有所不同,但标签将保持不变。

<people>
    <item id="1">
        <title>xxx</title>
        <phone>xxx</phone>
        <street>xxx</street>
        <city>xxx</city>
        <district>xxx</district>
    </item>
    <item id="2">
        <title>xxx</title>
        <phone>xxx</phone>
        <street>xxx</street>
        <city>xxx</city>
        <district>xxx</district>
    </item> 
<people>

我用NSXMLParser读取了这个XML。我想要做的是动态地将数据输入到数组中,例如:如果xml返回我带有单个标记的页面“item”数组将由单个item元素填充,而在字典中则会有其他标记(标题,电话,街道,城市,地区)。但是,在另一种情况下,如果标签“item”的数量更大,则数组将由更多元素“item”填充。

我希望我很清楚。

由于

1 个答案:

答案 0 :(得分:0)

你有没有尝试过NSMutableArray&amp;的NSMutableDictionary?

这样的伪代码:

NSMutableArray* tempArray = [NSMutableArray array];

for ( node in XML )
{
    if ( found new item )
    {
        NSMutableDictionary* tempDict = [NSMutableDictionary dictionary];
        for ( attribute in item )
        {
            [tempDict setObject:value forKey:key];
        }

        [tempArray addObject:tempDict];
    }
}