【问题标题】:how to put array elements on a table view cell如何将数组元素放在表格视图单元格上
【发布时间】:2013-01-24 05:30:52
【问题描述】:

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

这是一个解析器类

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

【问题讨论】:

    标签: ios objective-c arrays uitableview


    【解决方案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;
    
        }
    

    【讨论】:

    • @Tbt-lionArmanCapistrano:你使用了tableview委托吗? NSlog(@"%@",[theList.countryname]);
    • 它为空,list.countryname 中没有值。我该怎么办?
    • @Tbt-lionArmanCapistrano:您没有将国家/地区名称存储在数组中
    【解决方案2】:

    这行有问题:

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

    改成:

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

    【讨论】:

    • 我收到一个错误:(“无法识别的选择器发送到实例 0x71854a0'”
    猜你喜欢
    • 1970-01-01
    • 2014-02-28
    • 2013-12-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多