我想在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;
}
答案 0 :(得分:0)
好像你从未分配过NSMutableArray。你错过了:
_produktName = [NSMutableArray array];
这就是为什么addObject被发送到nil ..
答案 1 :(得分:0)
只需将您的getraenkeArray作为成员即可:
cell.produktName.text = [[getraenkeArray objectAtIndex:indexPath.row] getName];