0

I'm working on a Todo style app using Core Data and UITableView. I want the app icon on the home screen to show a badge for the number of entries in the TableView, but I'm having an issue. When I add a new cell, it updates fine. The badge matches the number of cells in the TableView, but the number on the badge doesn't decrease when I delete a cell. Does anyone know what I could do to make the badge update when I delete a cell, not just add one? Help would be greatly appreciated.

This is my current code:

NSInteger section = [self.tableView numberOfSections] - 1;
id <NSFetchedResultsSectionInfo> sectionInfo = [[self.fetchedResultsController sections]      objectAtIndex:section];
[[UIApplication sharedApplication] setApplicationIconBadgeNumber:[sectionInfo numberOfObjects]];

I have it in ViewWillAppear right under [super viewWillAppear:animated]; Is that the correct place to put it?

Thanks in advance for anyone that could help me out!

mhbdr
  • 753
  • 2
  • 10
  • 26

1 Answers1

1

Create an array of the items in your section, then use that as the badge number.

[[UIApplication sharedApplication] setApplicationIconBadgeNumber:[myArray count]];
WrightsCS
  • 50,551
  • 22
  • 134
  • 186