Delete from uitableview + write to plist not working

后端 未结 2 562
无人共我
无人共我 2021-01-26 00:51

i want to delete from uitableview and make it write to my plist. i\'m pretty new to this objective-c iOS coding, so forgive me for mistakes

Right now with my code it cra

2条回答
  •  谎友^
    谎友^ (楼主)
    2021-01-26 01:18

    You must change tableData after deleting, whereupon reload table view like this:

    [self.tableView reloadSections:[NSIndexSet  indexSetWithIndex:<#(NSUInteger)#>] withRowAnimation:<#(UITableViewRowAnimation)#>];//With animation
    

    or reload all table without animation:

    [self.tableView reloadData];
    

    instead of: [tableView beginUpdates];[tableView endUpdates];

    Need code:

      - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
    
        if (editingStyle == UITableViewCellEditingStyleDelete) {
    
        [tableData removeObjectAtIndex:indexPath.row];
    [arrayA setValue:tableData ForKey:@"Hostname"];
            [arrayA writeToFile:plistPath atomically: TRUE];
            [self.tableView reloadSections:[NSIndexSet  indexSetWithIndex:indexPath.section] withRowAnimation:UITableViewRowAnimationFade];
    
        }
        }
    

提交回复
热议问题