Uitableview显示对象

时间:2013-02-06 14:18:41

标签: iphone ios objective-c uitableview

我想在NSMutableArray中显示UITableView的值。在NSMutableArray中是对象的值。但是UITableView没有显示任何内容。如果我使用具有静态值的普通NSArray,则效果很好。

所以这是我的代码:

这是我的对象

@interface Getraenke_Object : NSObject {
    NSString *name;
}

我的NSMutableArray

NSMutableArray *getraenkeArray;

here is where I get the values into the array:
for(int i = 0; i < [getraenkeArray count]; i++)
    {    
        [_produktName addObject:[[getraenkeArray objectAtIndex:i]getName]];
        NSLog(@"test: %@",_produktName);
    }

这就是我尝试在UITableView

中显示它的方法
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"ProduktCell";
    ProduktTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    if (cell == nil) {
        cell = [[ProduktTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    }

    int row = [indexPath row];

    cell.produktName.text = _produktName [row];

    return cell;
}

2 个答案:

答案 0 :(得分:0)

好像你从未分配过NSMutableArray。你错过了:

_produktName = [NSMutableArray array];

这就是为什么addObject被发送到nil ..

答案 1 :(得分:0)

只需将您的getraenkeArray作为成员即可:

cell.produktName.text = [[getraenkeArray objectAtIndex:indexPath.row] getName];