ios - 如何将数组元素放在表格 View 单元格上

标签 ios objective-c arrays uitableview

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

这是一个解析器类

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

下面的代码是主视图 Controller

- (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 的新手,我希望有人能帮助我

最佳答案

试试看

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

    }

关于ios - 如何将数组元素放在表格 View 单元格上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14494609/

相关文章:

iphone - UITableViewCell 内容四处移动

javascript - 无法将数组显示到图表中

php - 将数组转换为字符串,然后返回 PHP

android - 为 PhoneGap 应用程序嵌入 PDF 查看器

iphone - 触发按钮操作时不会调用 ABNewPersonViewController 委托(delegate)方法

objective-c - UITextField onText 已更改

ios - 如果部署目标低于 iOS 7,状态栏样式的轻内容?

C++ 打印行号以及二维数组的最大行数

ios - 将 24 小时制日期对象转换为 12 小时制日期对象

iphone - 哪些对象添加到self.view后可以立即释放