简体   繁体   中英

How to delete a cell in a tableView

I am trying to let user delete a row in my app. But it is not working. I am new to app development so please help me.

 - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
 {
    [self.userSelectedNamesAndMeaning removeObjectForKey:indexPath];
    [self.userSelectedNamesAndMeaning writeToFile:self.pathToPlist atomically:YES];
    [self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];

    [tableView reloadData];
 }

I figured how to delete the Key value from the NSMutableDictionary and the solution is

   [self.userSelectedNamesAndMeaning removeObjectForKey:[self.allNames objectAtIndex:indexPath.row]];

Where allNames is the NSArray storing all the names to paint the table.

Now the problem is with deleting the row from the UI and it is showing an exception error.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM