如何将数组元素放在表视图单元格上

时间:2021-12-24 08:16:50

I've been trying to put the value of my array in my table view cells, it's multidimensional array how should i do it?

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

here's a parser class

这是一个解析器类

-(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];
    }

the code below is the mainviewcontroller

下面的代码是mainviewcontroller

- (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;

}

I just want the cell.textlabel to display the country name I'm just new in objective-c i hope someone can help me

我只是希望cell.textlabel显示国家名称我只是在Objective-c中我是新的,我希望有人可以帮助我

4 个解决方案

#1


5  

I think you should understand UITableView deeply before apply your data.

我认为你应该在应用数据之前深入了解UITableView。

This is very basic example: https://github.com/makadaw/UITableView-Sample

这是一个非常基本的例子:https://github.com/makadaw/UITableView-Sample

And investigate some examples from Apple: https://developer.apple.com/library/ios/#samplecode/TableViewSuite/Introduction/Intro.html#//apple_ref/doc/uid/DTS40007318

并调查Apple的一些示例:https://developer.apple.com/library/ios/#samplecode/TableViewSuite/Introduction/Intro.html#//apple_ref/doc/uid/DTS40007318

#2


1  

Just try

你试一试

- (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;

    }

#3


1  

here u can see better parsing tutorial as in your format.. http://www.theappcodeblog.com/2011/05/09/parsing-xml-in-an-iphone-app-tutorial/

在这里你可以看到更好的解析教程,如你的格式.. http://www.theappcodeblog.com/2011/05/09/parsing-xml-in-an-iphone-app-tutorial/

#4


1  

This line makes issue:

这一行有问题:

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

Change it to:

将其更改为:

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

#1


5  

I think you should understand UITableView deeply before apply your data.

我认为你应该在应用数据之前深入了解UITableView。

This is very basic example: https://github.com/makadaw/UITableView-Sample

这是一个非常基本的例子:https://github.com/makadaw/UITableView-Sample

And investigate some examples from Apple: https://developer.apple.com/library/ios/#samplecode/TableViewSuite/Introduction/Intro.html#//apple_ref/doc/uid/DTS40007318

并调查Apple的一些示例:https://developer.apple.com/library/ios/#samplecode/TableViewSuite/Introduction/Intro.html#//apple_ref/doc/uid/DTS40007318

#2


1  

Just try

你试一试

- (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;

    }

#3


1  

here u can see better parsing tutorial as in your format.. http://www.theappcodeblog.com/2011/05/09/parsing-xml-in-an-iphone-app-tutorial/

在这里你可以看到更好的解析教程,如你的格式.. http://www.theappcodeblog.com/2011/05/09/parsing-xml-in-an-iphone-app-tutorial/

#4


1  

This line makes issue:

这一行有问题:

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

Change it to:

将其更改为:

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