如何在标记的单元格中打印数组值?

时间:2011-07-13 10:40:47

标签: iphone objective-c ios

我正在开发一个应用程序,我希望在包含标签位置的单元格中打印数组值。我得到像names=[results valueForKey:@"name"].

这样的数组的值

我在cellForRowAtIndexPath中编写了一个用于打印该值的代码,如

-(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] autorelease];
    }
    NSInteger row=indexPath.row;

    cell = [self getCellContentView:CellIdentifier];
    UILabel *lblTemp1 = (UILabel *)[cell viewWithTag:1];
        lblTemp1.text = [names objectAtIndex:row];
    //lblTemp2.text = [names objectAtIndex:row];
    return cell;
}

但是,当应用程序在lblTemp1.text = [names objectAtIndex:row]收到错误时,如程序接收信号:“EXC_BAD_ACCESS”。所以请告诉我如何解决这个问题。

2 个答案:

答案 0 :(得分:1)

您似乎错过了保留数组名称。尝试,

names = [[results valueForKey:@"name"] retain];

您可以考虑使用声明的属性来克服保留和释放对象的开销。

答案 1 :(得分:0)

相关问题