How to add and delete section in UITableView - ios

I'm trying to delete section from UITableView.
Here is my code for adding object to array :
NSMutableArray *temp = [NSMutableArray new];
ClassName *section = [[ULPDPSection alloc] initWithTitle:#"Section-Title" rows:#[]];
[temp addObject:section];
self.sectionArray = [NSArray arrayWithArray:temp];
[self.tableView reloadData];
This is my numberOfRowsInSection code:
#property(nonatomic, strong) NSArray *sectionArray;
#property(nonatomic, strong) NSArray *rowsArray;//This is in ClassName
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
ClassName *section = [self.sectionArray objectAtIndex:section];
return section.rowsArray.count;
}
}
This is my code to delete section:
if(image.count < 5)
{
NSUInteger index = [self indexForSection:#"Section-Title"];
if(self.tableView.numberOfSections > index)
{
[self.tableView beginUpdates];
NSMutableArray *temp = [NSMutableArray arrayWithArray:self.sectionArray];
[temp removeObjectAtIndex:index];
[self.tableView deleteSections:[NSIndexSet indexSetWithIndex: index] withRowAnimation:UITableViewRowAnimationAutomatic];
[self.tableView endUpdates];
}
}
I'm getting crash message when trying to delete section:
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid update: invalid number of sections. The number of sections contained in the table view after the update (5) must be equal to the number of sections contained in the table view before the update (5), plus or minus the number of sections inserted or deleted (0 inserted, 1 deleted).'

Related

Invalid update: invalid number of rows in section

I am working on a project using Microsoft Azure services. In that while deleting a row I am getting this error:
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 (2) must be equal to the number of rows
contained in that section before the update (2), 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 for table load and delete row is as :
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 3;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
//medicine list
if (section == 0) {
NSArray *sectionInfo = [self.fetchedResultsController1 fetchedObjects];
return [sectionInfo count];
}
//allergy list
else if (section == 1) {
NSArray *sectionInfo = [self.fetchedResultsController2 fetchedObjects];
return [sectionInfo count];
}
//notes list
else if (section == 2){
NSArray *sectionInfo = [self.fetchedResultsController3 fetchedObjects];
return [sectionInfo count];
}
else
return 0;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *cellIdentifier = #"mcell";
MedicationTableViewCell *cell = (MedicationTableViewCell *) [tableView dequeueReusableCellWithIdentifier:cellIdentifier forIndexPath:indexPath];
// Add utility buttons
NSMutableArray *rightUtilityButtons = [NSMutableArray new];
[rightUtilityButtons sw_addUtilityButtonWithColor: [UIColor colorWithRed:1.0f green:0.231f blue:0.188 alpha:1.0f] title:#"Delete"];
switch (indexPath.section) {
case 0: {
NSManagedObject *item = [self.fetchedResultsController1 objectAtIndexPath:indexPath];
cell.textLabel.text = [item valueForKey:#"name"];
break;
}
case 1: {
NSManagedObject *item = [self.fetchedResultsController2 objectAtIndexPath:[NSIndexPath indexPathForRow:indexPath.row inSection:0]];
cell.textLabel.text = [item valueForKey:#"name"];
break;
}
case 2: {
NSManagedObject *item = [self.fetchedResultsController3 objectAtIndexPath: [NSIndexPath indexPathForRow:indexPath.row inSection:0]];
cell.textLabel.text = [item valueForKey:#"title"];
break;
}
default:
break;
}
cell.rightUtilityButtons = rightUtilityButtons;
cell.delegate = self;
return cell;
}
- (void)swipeableTableViewCell:(SWTableViewCell *)cell didTriggerRightUtilityButtonWithIndex:(NSInteger)index {
// Delete button is pressed
NSIndexPath *cellIndexPath = [self.medicationsTableView indexPathForCell:cell];
//fetchingg data from local store first
NSManagedObject *item = [self.fetchedResultsController1 objectAtIndexPath:[NSIndexPath indexPathForRow:cellIndexPath.row inSection:0]];
NSMutableArray *keys = [[NSMutableArray alloc] initWithObjects:#"id", #"name", #"userId", nil];
NSMutableArray *values = [[NSMutableArray alloc] initWithObjects: [item valueForKey:#"id"], [item valueForKey:#"name"], [item valueForKey:#"userId"], nil];
//creating dictionary of data
NSDictionary *dict = [[NSDictionary alloc] initWithObjects:values forKeys:keys];
//calling delete fucntion
[self.authService deleteItem:self.syncTable withDict:dict completion:^{
//removing row from table view
[self.medicationsTableView reloadData];
[self.medicationsTableView deleteRowsAtIndexPaths:#[cellIndexPath] withRowAnimation:UITableViewRowAnimationRight];
}];
break;
}
Please tell where I am going wrong. Thanks in advcance!!!!
In - (void)swipeableTableViewCell: didTriggerRightUtilityButtonWithIndex:
You need to remove either
[self.medicationsTableView reloadData];
or
[self.medicationsTableView deleteRowsAtIndexPaths:#[cellIndexPath] withRowAnimation:UITableViewRowAnimationRight];
Because on first line when reloadData get called it's reload the tableview with new datasource and again calling deleteRowsAtIndexPaths tried to delete a rows which already removed by calling reloadData earlier.
The important thing is that you need to use either
[self.medicationsTableView reloadData];
or
[self.medicationsTableView deleteRowsAtIndexPaths:#[cellIndexPath] withRowAnimation:UITableViewRowAnimationRight];
The reason being, when the tableview's reload data is called the row which is removed from data source is deleted and after that when the delete row api is called for the same index path(where the row is already deleted causes the issue)
Also just before deleting the row from the table delete the object from the data source (self.fetchedResultsController1) and call
[self.medicationsTableView deleteRowsAtIndexPaths:#[cellIndexPath] withRowAnimation:UITableViewRowAnimationRight];
and after the above row's deletion animation is completed than you can call(but it is not required)
[self.medicationsTableView reloadData];

Assertion failure in UITableView _endCellAnimationsWithContext [duplicate]

This question already has answers here:
'Invalid update: invalid number of rows in section 0
(4 answers)
Closed 8 years ago.
i have a problem like this :
i am loading some data to a table view after select a date from a date picker.the data which i want to load is loaded to a variable inside the didSelectRowAtIndexPath method. when the table is checking for the number of rows it checks the count of that variable is grater than zero and so on..
my problem is this : when i load the data to the variable by calling a web service [using AFNetworking library] it is works nicely. but when i get the data directly [i have implemented a method to call web service before the table load, and holds the data] by a method it is giving this error
Assertion failure in -[UITableView _endCellAnimationsWithContext:], /SourceCache/UIKit_Sim/UIKit-2903.23/UITableView.m:1330
2014-05-02 17:25:12.665 varrdle_v2[1428:a0b] * 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 (3) must be equal to the number of rows contained in that section before the update (2), 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).
* First throw call stack:
i cant figure out why that happens. the only different is the way i taken the data.
below is my implementation
number of rows
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
NSArray* reqFdate= [TableViewController getrequestPerDate];
NSLog(#"Count OF REQUESTS: %d",reqFdate.count);
if (reqFdate.count == 0 ) {
NSInteger numberOfRows = [self.persons count];
if ([self datePickerIsShown]){
numberOfRows++;
}
NSLog(#"NO OF ROWS in IF %d",numberOfRows);
return numberOfRows;
}
else{
NSLog(#"NO OF ROWS %d",reqFdate.count);
return reqFdate.count;
}
}
cell for row at indexpath
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell;
NSDate *today = [NSDate date];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
// display in 12HR/24HR (i.e. 11:25PM or 23:25) format according to User Settings
[dateFormatter setTimeStyle:NSDateFormatterShortStyle];
NSString *currentTime = [dateFormatter stringFromDate:today];
NSDate *date=[dateFormatter dateFromString:currentTime];
if(indexPath.row==0){
VCPerson *person = self.persons[0];
cell = [self createPersonCell:person];
}
else if ([self datePickerIsShown] && (self.datePickerIndexPath.row == 1)){
// VCPerson *person = self.persons[indexPath.row -1];
cell = [self createPickerCell:date];
}
else{
TacleCell *cell = (TacleCell*)[self.tableView dequeueReusableCellWithIdentifier:otherCellID];
cell.delegate = self;
if(cell == nil)
{
cell = [[TacleCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:otherCellID];
}
else
{
//cancel loading previous image for cell
[[AsyncImageLoader sharedLoader] cancelLoadingImagesForTarget:cell.profileImage];
}
return cell;
}
return cell;
}
didSelect method
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[self.tableView beginUpdates];
int countOfRowss = [TableViewController getrequestPerDate].count;
if(countOfRowss>0)
{
NSArray* indexpathsArry = [self getIndexPaths];
[self.tableView deleteRowsAtIndexPaths:indexpathsArry withRowAnimation:YES];
requestForDate = nil;
}
if ([self datePickerIsShown] && (self.datePickerIndexPath.row - 1 == indexPath.row)){
[self hideExistingPicker];
//[self.tableView reloadData];
//[self viewDidLoad];
//call the service and take the results
NSString* selecteDate = [TableViewController getDate];
//NSString* prsonID =[LoginView getPersonID];
// here i call this method and get the data.
requestForDate= [self filterRequestForDate:selecteDate];
NSLog(#"FILTERED REQUESTS :%#",requestForDate);
//requestForDate = nil;
[self.tableView reloadData];
// NSString* selecteDate = [ScheduleView getDate];
// this is how i fetch the data by using a web service
/* NSString* prsonID =[LoginView getPersonID];
NSDictionary* parms = [NSDictionary dictionaryWithObjectsAndKeys:prsonID,#"caregiverPersonId",selecteDate,#"selectedDate", nil];
jsonpaser* jp = [[jsonpaser alloc]init];
//[self.indicator_process startAnimating];
[jp getWebServiceResponce:#"myUrl" :parms success:^(NSDictionary *responseObject)
{
requestForDate = responseObject;
NSLog(#"RESPONSEFORDATE_IN DIDSELECT :%#",requestForDate);
NSArray* indexpaths = [self getIndexPaths];
NSLog(#"indexPATHS %#",indexpaths);
//[self.indicator_process stopAnimating];
//[_dimmingView removeFromSuperview];
[self.tableView reloadData];
}];
*/
}
else{
//--
NSIndexPath *newPickerIndexPath = [self calculateIndexPathForNewPicker:indexPath];
if ([self datePickerIsShown]){
[self hideExistingPicker];
}
[self showNewPickerAtIndex:newPickerIndexPath];
self.datePickerIndexPath = [NSIndexPath indexPathForRow:newPickerIndexPath.row + 1 inSection:0];
NSLog(#"DATEPICKERINDEX %#",self.datePickerIndexPath);
//self.datePickerIndexPath = nil;
}
// this is the line where a row deleted
[self.tableView deselectRowAtIndexPath:indexPath animated:YES];
[self.tableView endUpdates];
}
please someone tell me where is the issue...
thank you
Regarding to apple documentation apple link you should not call reloadData between beginUpdates and endUpdates.
You should remove the beginUpdates and endUpdates or move the reloadData outside the group.

Crashes with UITableView

I am displaying an array objects in a UITableView with inserts, updated and deletes and occasionally I get the exception below even though I am carefully handling the changes. I have the full code example on GitHub.
https://github.com/brennanMKE/TableMaddness
This sample project uses objects which implement NSCoding and NSCopying as well as isEqual so that updating the table with inserts, updates and deletes can simulate what I am doing in a real app which is having the same problem. I am avoiding using Core Data which would use NSFetchedResultsController so I'd like know if there is something I should use if I am not using Core Data.
Assertion failure in -[UITableView _endCellAnimationsWithContext:], /SourceCache/UIKit_Sim/UIKit-2903.23/UITableView.m:1330
2013-11-25 14:43:20.217 TableMaddness[13411:70b] 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 (4) must be equal to the number of rows contained in that section before the update (4), plus or minus the number of rows inserted or deleted from that section (1 inserted, 0 deleted) and plus or minus the number of rows moved into or out of that section (0 moved in, 0 moved out).'
Below is the related code.
// determine items which need to be inserted, updated or removed
NSMutableArray *inserts = [#[] mutableCopy];
NSMutableArray *deletes = [#[] mutableCopy];
NSMutableArray *reloads = [#[] mutableCopy];
// look for inserts
for (NSUInteger row=0; row<fetchedItems.count; row++) {
SSTItem *item = fetchedItems[row];
if (![self.currentItems containsObject:item]) {
// inserts are items which are not already in self.items
[inserts addObject:[NSIndexPath indexPathForRow:row inSection:0]];
}
else {
NSUInteger otherIndex = [self.currentItems indexOfObject:item];
SSTItem *otherItem = [self.currentItems objectAtIndex:otherIndex];
if (![item.modified isEqualToDate:otherItem.modified]) {
[reloads addObject:[NSIndexPath indexPathForRow:row inSection:0]];
}
}
}
// look for deletes
for (NSUInteger row=0; row<self.currentItems.count; row++) {
SSTItem *item = self.currentItems[row];
if (![fetchedItems containsObject:item]) {
[deletes addObject:[NSIndexPath indexPathForRow:row inSection:0]];
}
}
static NSString *lock = #"LOCK";
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (kDelay / 4) * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
// lock is required to prevent inconsistencies when changing view orientation during rotation
#synchronized(lock) {
self.currentItems = fetchedItems;
NSUInteger numberOfRowsInSection = [self tableView:self.tableView numberOfRowsInSection:0];
DebugLog(#"numberOfRowsInSection: %li", numberOfRowsInSection);
DebugLog(#"self.items: %li", self.currentItems.count);
MAAssert(self.currentItems.count == numberOfRowsInSection, #"Match is required");
if (inserts.count || deletes.count || reloads.count) {
[self.tableView beginUpdates];
#ifndef NDEBUG
for (NSIndexPath *indexPath in inserts) {
DebugLog(#"Inserting at %li", (long)indexPath.row);
}
for (NSIndexPath *indexPath in deletes) {
DebugLog(#"Deleting at %li", (long)indexPath.row);
}
for (NSIndexPath *indexPath in reloads) {
DebugLog(#"Reloading at %li", (long)indexPath.row);
}
#endif
[self.tableView insertRowsAtIndexPaths:inserts withRowAnimation:UITableViewRowAnimationAutomatic];
[self.tableView deleteRowsAtIndexPaths:deletes withRowAnimation:UITableViewRowAnimationAutomatic];
[self.tableView reloadRowsAtIndexPaths:reloads withRowAnimation:UITableViewRowAnimationAutomatic];
[self.tableView endUpdates];
}
}
index++;
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, kDelay * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
[self runNextUpdate];
});
});
- (void)runNextUpdate {
if (index >= self.dataSets.count) {
index = 0;
[self runNextUpdate]; // remove this line
return; // or add this line.
}
Because if this condition is true, your code will run twice almost at the same time, but the data source has not been updated.

crash while removing cell from table view

- (void)tableView:(UITableView *)tv commitEditingStyle:(UITableViewCellEditingStyle)editingStyle
forRowAtIndexPath:(NSIndexPath *)indexPath {
if(editingStyle == UITableViewCellEditingStyleDelete) {
//Get the object to delete from the array.
NSLog(#"%#",[[_arrayForTable valueForKey:#"IDS"] objectAtIndex:[indexPath row]] );
NSInteger myInteger = [[[_arrayForTable valueForKey:#"IDS"] objectAtIndex:[indexPath row]] integerValue];
NSNumber *selRow = [NSNumber numberWithInt:myInteger];
NSLog(#"%#",selRow);
[self removeCell:selRow]; // this is working perfectly it gets remove from database
//Delete the object from the table.
// app get crash here crash report is pested below
[self.table deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
}
}
- (void) removeCell:(NSNumber *)selRow{
NSLog(#"_arrayForTable%#",_arrayForTable);
NSInteger myInteger = [selRow integerValue];
[_arrayForTable removeObjectAtIndex:myInteger];
NSLog(#"_arrayForTable%#",_arrayForTable);
if(deleteStmt == nil) {
const char *sql = "delete from PersonNamesAndBirthDates where ID = ?";
NSLog(#"%s",sql);
if(sqlite3_prepare_v2(database1, sql, -1, &deleteStmt, NULL) != SQLITE_OK)
NSAssert1(0, #"Error while creating delete statement. '%s'", sqlite3_errmsg(database1));
}
NSLog(#"%d",myInteger);
//When binding parameters, index starts from 1 and not zero.
sqlite3_bind_int(deleteStmt, 1, myInteger );
if (SQLITE_DONE != sqlite3_step(deleteStmt))
NSAssert1(0, #"Error while deleting. '%s'", sqlite3_errmsg(database1));
sqlite3_reset(deleteStmt);
}
* Assertion failure in -[UITableView _endCellAnimationsWithContext:], /SourceCache/UIKit_Sim/UIKit-1912.3/UITableView.m:1046 2013-04-08
17:01:13.069 birthdate reminder 2[583:15803] * 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 (12) must be
equal to the number of rows contained in that section before the
update (12), 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).'
please suggest something
my numberofrow method is below
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
return _arrayForTable.count;
}
app is not crashing everytime sometime works sometime crash
Ok, so as I see it, you are getting the ID of a specific row with:
NSInteger myInteger =
[[[_arrayForTable valueForKey:#"IDS"] objectAtIndex:[indexPath row]] integerValue];
NSNumber *selRow = [NSNumber numberWithInt:myInteger];
And then, you're using the ID of that specific row, as the index to remove it from the array.
NSInteger myInteger = [selRow integerValue];
[_arrayForTable removeObjectAtIndex:myInteger];
That's where things go wrong. If the array has the same order as your TableView, you need to remove indexPath.row from it. The ID is necessary for your database.
Try this:
- (void)tableView:(UITableView *)tv commitEditingStyle :(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
if(editingStyle == UITableViewCellEditingStyleDelete) {
//Get the object to delete from the array.
NSLog(#"%#",[[_arrayForTable valueForKey:#"IDS"] objectAtIndex:[indexPath row]] );
NSInteger myInteger = [[[_arrayForTable valueForKey:#"IDS"] objectAtIndex:[indexPath row]] integerValue];
NSNumber *selRow = [NSNumber numberWithInt:myInteger];
NSLog(#"%#",selRow);
[self.table beginUpdates];
[self removeCell:selRow]; // this is working perfectly it gets remove from database
//Delete the object from the table.
// app get crash here crash report is pested below
[self.table deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
[self.table endUpdates];
}
}
Notice the [self.table beginUpdates]; and [self.table endUpdates]; around the lines of code which alter the tableview.
IT"S WORKING
at and of your commitEditingStyle method add this line
[TableViewForFirstView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];

Error while deleting a section from my UITableView

I need your help :(
I'm working on a iOS application in which i had to remove some rows and sections in a UItableView.
I'm on Xcode 4.
I associate my tableView with NSarray and dictionary, like this :
NSMutableArray *arrTemp1 = [[NSMutableArray alloc]
initWithObjects:#"Chris",nil];
NSMutableArray *arrTemp2 = [[NSMutableArray alloc]
initWithObjects:#"Bianca",nil];
NSMutableArray *arrTemp3 = [[NSMutableArray alloc]
initWithObjects:#"Candice",#"Clint",#"Chris",nil];
NSMutableArray *arrTemp4 = [[NSMutableArray alloc]
initWithObjects:#"Candice",#"Clint",#"Chris",nil];
NSMutableArray *arrTemp5 = [[NSMutableArray alloc]
initWithObjects:#"Candice",#"Clint",#"Chris",nil];
NSMutableArray *arrTemp6 = [[NSMutableArray alloc]
initWithObjects:#"Candice",#"Clint",#"Chris",nil];
NSMutableDictionary *temp = [[NSMutableDictionary alloc]
initWithObjectsAndKeys:arrTemp1,#"A",arrTemp2,
#"B",arrTemp3,#"C",arrTemp4, #"D", arrTemp5, #"E", arrTemp6, #"J",nil];
self.tableContents = temp;
self.sortedKeys =[[self.tableContents allKeys]
sortedArrayUsingSelector:#selector(compare:)];
When i need to delete a rows or a sectionm i'm using this code ->
(void)tableView:(UITableView *)tableView
commitEditingStyle:(UITableViewCellEditingStyle)editingStyle
forRowAtIndexPath:(NSIndexPath *)indexPath
{
if (editingStyle == UITableViewCellEditingStyleDelete)
{
NSMutableArray *listData = [self.tableContents objectForKey:
[self.sortedKeys objectAtIndex:[indexPath section]]];
NSUInteger row = [indexPath row];
[listData removeObjectAtIndex:row];
[tableView beginUpdates];
if ([listData count] > 0)
{
// Section is not yet empty, so delete only the current row.
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath]
withRowAnimation:UITableViewRowAnimationFade];
}
else
{
// Section is now completely empty, so delete the entire section.
[tableView deleteSections:[NSIndexSet indexSetWithIndex:indexPath.section]
withRowAnimation:UITableViewRowAnimationFade];
}
[tableView endUpdates];
}
}
When i'm deleting rows, it works well..
When i'm deleting sections, i'm getting the following error :
" * Assertion failure in -[UITableView _endCellAnimationsWithContext:], /SourceCache/UIKit/UIKit-1912.3/UITableView.m:1030
2012-01-13 16:42:45.261 * Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid update: invalid number of sections. The number of sections contained in the table view after the update (6) must be equal to the number of sections contained in the table view before the update (6), plus or minus the number of sections inserted or deleted (0 inserted, 1 deleted).'"
(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return [tableContents count]; // tableContent is a NSMUtableDictionnary*
}
- (NSInteger)tableView:(UITableView *)table
numberOfRowsInSection:(NSInteger)section
{
NSArray *listData =[self.tableContents objectForKey:
[self.sortedKeys objectAtIndex:section]];
return [listData count];
}
I'm getting crazy, and coming on stackOverflow to ask for help...
(Sorry for my poor english :( )
Thanks to everyone reading and answering !!
It looks like you're not actually deleting the dictionary key for the empty array when it contains no objects, thus your call to
// Section is now completely empty, so delete the entire section.
[tableView deleteSections:[NSIndexSet indexSetWithIndex:indexPath.section]
withRowAnimation:UITableViewRowAnimationFade];
is causing the problem as you still have the same number of sections (dictionary keys) as before...
Try swapping these 2 lines around:
[listData removeObjectAtIndex:row];
[tableView beginUpdates];
So it should be:
[tableView beginUpdates];
[listData removeObjectAtIndex:row];

Resources