Iphone 创建动态UITableView

Iphone 创建动态UITableView,iphone,xml,arrays,xcode,Iphone,Xml,Arrays,Xcode,大家好,StackOverflow的朋友们,我遇到了另一个问题,我将尝试与你们一起解决。假设我有这个XML,它的字段每次都会不同,但标记将保持不变 <people> <item id="1"> <title>xxx</title> <phone>xxx</phone> <street>xxx</street> <city&g

大家好,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>

xxx
xxx
xxx
xxx
xxx
xxx
xxx
xxx
xxx
xxx
我使用NSXMLParser阅读了这个XML。我想做的是动态地将数据输入一个数组,例如:如果xml返回我,带有单个标记“item”数组的页面将由单个item元素填充,而在字典中会有其他标记(title、phone、street、city、district)。但是,在另一种情况下,如果标记“item”的数量较大,则数组将由更多的元素“item”填充

我希望我是清楚的


谢谢

您尝试过NSMutableArray和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];
    }
}

那么你的具体问题是什么?你试过什么?什么有效,什么无效?我的问题是我不知道如何动态填充数组,将字段“item”作为字段。在XML解析器中,创建一个可变数组,每当遇到“item”时,向数组中添加另一个对象。问题是我不知道如何在查找项时创建字段,我不明白如何才能找到第一项、第二项等。