NSMutableDictionary 不更新 tableView
NSMutableDictionary not updating the tableView
我有这个密码给edit/delete汽车
- (void)dismissViewWithIndex:(NSInteger)index selectedVehicle:(NSInteger)selectedVehicle toDelete:(BOOL)toDelete {
if (toDelete && [self.cars count] > 0) {
[self.cars removeObjectAtIndex:(index-1)];
} else {
NSMutableDictionary *editCar =[NSMutableDictionary dictionaryWithDictionary:[self.cars objectAtIndex:index-1]];
editCar[@"vehicleType"] = selectedVehicle == 0 ? @"SmallTruck" : @"BigTruck";
}
[self.tableView reloadData];
}
我有这个代表来更新表格视图
#pragma mark - Delegate
- (void)updateSelectedVehicle:(BOOL)toDelete {
[self.delegate dismissViewWithIndex:(int)self.selectedCarIndex selectedVehicle:self.vehiclePreviousIndexPath.item toDelete:toDelete];
[self.navigationController popViewControllerAnimated:YES];
}
但似乎即使在控制台中显示选定的索引后它也不会change/or更新表视图。
您只是在修改局部变量的值。这将解决您的问题。
NSMutableArray *cars = [[NSMutableArray alloc] initWithArray:self.cars];
NSMutableDictionary *editCar =[NSMutableDictionary dictionaryWithDictionary:[self.cars objectAtIndex:index-1]];
editCar[@"vehicleType"] = selectedVehicle == 0 ? @"SmallTruck" : @"BigTruck";
[cars replaceObjectAtIndex:index-1 withObject:editCar];
self.cars = cars;
我有这个密码给edit/delete汽车
- (void)dismissViewWithIndex:(NSInteger)index selectedVehicle:(NSInteger)selectedVehicle toDelete:(BOOL)toDelete {
if (toDelete && [self.cars count] > 0) {
[self.cars removeObjectAtIndex:(index-1)];
} else {
NSMutableDictionary *editCar =[NSMutableDictionary dictionaryWithDictionary:[self.cars objectAtIndex:index-1]];
editCar[@"vehicleType"] = selectedVehicle == 0 ? @"SmallTruck" : @"BigTruck";
}
[self.tableView reloadData];
}
我有这个代表来更新表格视图
#pragma mark - Delegate
- (void)updateSelectedVehicle:(BOOL)toDelete {
[self.delegate dismissViewWithIndex:(int)self.selectedCarIndex selectedVehicle:self.vehiclePreviousIndexPath.item toDelete:toDelete];
[self.navigationController popViewControllerAnimated:YES];
}
但似乎即使在控制台中显示选定的索引后它也不会change/or更新表视图。
您只是在修改局部变量的值。这将解决您的问题。
NSMutableArray *cars = [[NSMutableArray alloc] initWithArray:self.cars];
NSMutableDictionary *editCar =[NSMutableDictionary dictionaryWithDictionary:[self.cars objectAtIndex:index-1]];
editCar[@"vehicleType"] = selectedVehicle == 0 ? @"SmallTruck" : @"BigTruck";
[cars replaceObjectAtIndex:index-1 withObject:editCar];
self.cars = cars;