0

我一直试图将我的数组的值放在我的表格视图单元格中,它是多维数组我应该怎么做?

这是一个解析器类

-(void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName
{
if ([elementName isEqualToString:@"subsidiary"])
{
      NSLog(@"%i", [app.infoarray count]);
    [app.listArray addObject:app.infoarray];
    [app.infoarray removeAllObjects];

}
else
{
     if ([elementName isEqualToString:@"countryname"])
     {
         temp = currentElementValue;

     }
    if ([elementName isEqualToString:@"name"])
    {

        theList.name = currentElementValue;
        [app.infoarray addObject:theList.name];
    }
    if ([elementName isEqualToString:@"address"])
    {
        theList.address = currentElementValue;
        [app.infoarray addObject:theList.address];
    }

下面的代码是主视图控制器

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
}

theList.countryname = [app.listArray objectAtIndex:0];
cell.textLabel.text= theList.countryname; ////<<WHAT SHOULD I DO HERE?
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
return cell;

}

我只想让 cell.textlabel 显示国家/地区名称我只是 Objective-c 中的新手我希望有人可以帮助我

4

2 回答 2

1

这一行提出了问题:

theList.countryname = [app.listArray objectAtIndex:0];

将其更改为:

theList.countryname = [[app.listArray objectAtIndex:indexPath.row] objectAtindex:0];
于 2013-01-24T05:41:38.730 回答
1

试试看嘛

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    }

    theList.countryname = [app.listArray objectAtIndex: indexPath.row];
    cell.textLabel.text= theList.countryname;
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    return cell;

    }
于 2013-01-24T05:36:26.410 回答