Note that there are some explanatory texts on larger screens.

plurals
  1. PODelete cell in tableView with Plist
    primarykey
    data
    text
    <p>I want to delete a cell in one of my 2 tableViews (1 is the main one, 2 the Favorites one).</p> <p>To delete a cell, i should set a specific value to "NO", in order to be NO in the plist (the Favorite table shows only cells with "isFav" value set to YES). </p> <p>Check this question for further details: <a href="https://stackoverflow.com/questions/11157692/uitableview-not-showing-the-right-cells">UITableView not showing the right cells</a></p> <p>Back to my question, i tried to do</p> <pre><code>- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath { NSArray *plist = [self readPlist]; NSMutableDictionary *theItem = [[[plist objectAtIndex:indexPath.section] valueForKey:@"Rows"] objectAtIndex:indexPath.row]; NSLog(@"%@",theItem); if (editingStyle == UITableViewCellEditingStyleDelete) { [theItem setValue:[NSNumber numberWithBool:NO] forKey:@"isFav"]; [self.tableView deleteRowsAtIndexPaths:[[[NSArray arrayWithObject:[plist objectAtIndex:indexPath.section]]valueForKey:@"Rows"]objectAtIndex:indexPath.row] withRowAnimation:UITableViewRowAnimationNone]; [self writePlist:plist]; [self.tableView reloadData]; } } - (void)writePlist:(NSArray*)arr { NSArray *documentPaths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES); NSString *plistPath = [[documentPaths lastObject] stringByAppendingPathComponent:@"tipsList.plist"]; NSFileManager *fMgr = [NSFileManager defaultManager]; if ([fMgr fileExistsAtPath:plistPath]) [fMgr removeItemAtPath:plistPath error:nil]; [arr writeToFile:plistPath atomically:YES]; } - (NSArray*)readPlist { NSArray *documentPaths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES); NSString *plistPath = [[documentPaths lastObject] stringByAppendingPathComponent:@"tipsList.plist"]; NSFileManager *fMgr = [NSFileManager defaultManager]; if (![fMgr fileExistsAtPath:plistPath]) { plistPath = [[NSBundle mainBundle] pathForResource:@"tipsList" ofType:@"plist"]; } NSMutableArray *returnArr = [NSMutableArray arrayWithContentsOfFile:plistPath]; NSPredicate *predicate = [NSPredicate predicateWithFormat:@"isFav == YES"]; for (NSDictionary *sect in returnArr) { NSArray *arr = [sect objectForKey:@"Rows"]; [sect setValue:[arr filteredArrayUsingPredicate:predicate] forKey:@"Rows"]; [self.tableView reloadData]; } return returnArr; } </code></pre> <p>but with no success. What was i trying to do: trying to get to the current item in the table, then set its "isFav" value to NO and then delete the cell from the table, but i'm failing, getting</p> <pre><code> *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFDictionary row]: unrecognized selector sent to instance 0x7fd4ab0' </code></pre> <p>I tried to do <code>[NSArray arrayWithObject:indexPath]</code> but i get </p> <pre><code>Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid update: invalid number of rows in section 0. The number of rows contained in an existing section after the update (1) must be equal to the number of rows contained in that section before the update (1), plus or minus the number of rows inserted or deleted from that section (0 inserted, 1 deleted) and plus or minus the number of rows moved into or out of that section (0 moved in, 0 moved out).' </code></pre> <p>Any help appreciated :| </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload