我正在使用NSMutableArray填充我的tableview中的单元格。问题是,当我尝试将一个对象添加到我的数组中时,它将所有对象替换为已添加的对象,所以我总是只有一个对象在我的数组中。正因为如此,每当调用下面的方法时,我的tableview总是只有一个单元格被覆盖。我错过了什么吗?如何将对象添加到数组?
_selectedThingArray = [[NSMutableArray alloc] init];
_currentThing = newThing;
//Note: newThing is the object being passed when this method is called.
//It is the new data that will should passed into the cell.
[_selectedThingArray addObject:_currentThing];
NSLog(@"%@", newThing);
NSLog(@"array: %@", _selectedThingArray);
[self.tableView reloadData];
你确定你不在你的代码中的其他地方修改你的数组吗? – NightFury
我认为你只是在添加对象的方法中重新创建数组... _selectedThingArray = [[NSMutableArray alloc] init]; ,将创建移动到初始化方法 –
每次调用上述操作时,都会启动'_selectedThingArray'。奇怪的是,这意味着它只会包含一个项目。 –