簡體   English   中英

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];
}

但似乎即使在控制台中顯示選定的索引后,它也不會更改/或更新 tableview。 在此處輸入圖像描述

您只是在修改局部變量的值。 這將解決您的問題。

    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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM