Removing images when deleting row from table view


#1

I notice that there is no code to deal with images stored on the disk when a possession is removed from the table view. Wouldn’t this end up in bloating the storage for this application by leaving orphaned images in the Documents directory for our application?

Would modifying this code in the tableView:commitEditingStyle:forRowAtIndexPath: method in the ItemsViewController and the matching #import statement be the correct way to deal with this?

if (editingStyle == UITableViewCellEditingStyleDelete) {
	// Remove image from permanent storage
	Possession *possession = [possessions objectAtIndex:[indexPath row]];
	[[ImageCache sharedImageCache] deleteImageForKey:[possession imageKey]];

	// Remove possession from array
	[possessions removeObjectAtIndex:[indexPath row]];
	[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
}

Or have I missed something?


#2

Yup, that looks like the way to do it.

Sometimes we don’t include things to “finish off” an application when there isn’t really anything iPhone specific left to teach.


#3

Thanks Joe. I just wanted to make sure there wasn’t some magic that I was missing.