[英]NSMutableArray and NSMutableDictionary in a 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];
}
您只是在修改局部變量的值。 這將解決您的問題。
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;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.