提问人:Jann 提问时间:2/16/2021 最后编辑:Jann 更新时间:2/16/2021 访问量:30
NSMutableDictionary 未更新 tableView
NSMutableDictionary not updating the tableView
问:
我有这个代码来编辑/删除汽车
- (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];
}
答:
1赞
Thilina Chamath Hewagama
2/16/2021
#1
您只是在修改局部变量的值。这将解决您的问题。
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;
评论