Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

ljg93

macrumors member
Original poster
Mar 13, 2011
98
0
Code:
- (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])) {
			return;
		}
		
		[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];
		
	}
}
 
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.
http://developer.apple.com/library/...ging_Applications/debugging_applications.html

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.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.