why does this not delete?

Discussion in 'iOS Programming' started by ljg93, Mar 17, 2011.

  1. ljg93 macrumors member

    Mar 13, 2011
    - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle		
    	forRowAtIndexPath:(NSIndexPath *)indexPath {
    	if (editingStyle == UITableViewCellEditingStyleDelete) {
    		NSMutableArray *allTitles = [categories objectForKey:[NSString stringWithFormat:@"%@ Titles", self.title]];
    		NSMutableArray *customTitles = [NSMutableArray arrayWithArray:
    										[[NSUserDefaults standardUserDefaults] 
    										 arrayForKey:[NSString stringWithFormat:@"Custom Titles %@", self.title]]];
    	if (indexPath.row >=([allTitles count] - [customTitles count])) {
    		[customTitles removeObjectAtIndex:indexPath.row - (allTitles.count - customTitles.count)];
    		[[NSUserDefaults standardUserDefaults] setObject:customTitles forKey:[NSString stringWithFormat:@"Custom Titles %@", self.title]];
    		[[categories objectForKey:[NSString stringWithFormat:@"%@ Titles", self.title]] removeObjectAtIndex:indexPath.row];
    		[cellTitles removeObjectAtIndex:indexPath.row];
    		[tableView reloadData];
  2. (marc) macrumors 6502a


    Sep 15, 2010
    the woods
  3. chown33 macrumors 604

    Aug 9, 2009
    Sailing beyond the sunset
    Learn to use the debugger. You can't avoid it forever, so the sooner you start learning it the better.

    You need to confirm that what you think should happen is actually happening. Those places that return an array? Make sure they return an array. The places where you expect an array count to be non-zero? Confirm the count is non-zero. The places that return a value from objectForKey? Make sure a non-nil object is returned.

    To do all those things with the debugger, set a breakpoint on that method. Then step through a line at a time and confirm that each value is what you expect it to be.

    If you don't know how to do that, start with the debugger introduction.

    If your current project is too complicated to set a breakpoint in, then make a simple project where you can train yourself on using the debugger. You can even add intentional bugs that let you practice specific things with the debugger, like inspecting the values of variables and stepping through lines.

    Pilots in training don't fly a jet aircraft on day one, or even day 20. They take classes, they practice in simulators, they fly in training aircraft. Train to use the tools first, and you'll be much less likely to crash and burn.

Share This Page