0

I want to display the values of a NSMutableArray in a UITableView. In the NSMutableArray are values of objects. But the UITableView doesn't display anything. If I use a normal NSArray with static values it works well.

So this is my code:

This is my object

@interface Getraenke_Object : NSObject {
    NSString *name;
}

my 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);
    }

and that is how I try to display it in the 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;
}
4

2 回答 2

0

it seems like you never allocated the NSMutableArray. you are missing:

_produktName = [NSMutableArray array];

and that's why the addObject is being sent to nil..

于 2013-02-06T14:22:30.330 回答
0

Just make your getraenkeArray as member and:

cell.produktName.text = [[getraenkeArray objectAtIndex:indexPath.row] getName];
于 2013-02-06T14:27:20.313 回答