I can't delete cell in the resultant table in normal everything is OK and after search gives out an error
Assertion failure in -[UISearchResultsTableView
_endCellAnimationsWithContext:], /BuildRoot/Library/Caches/com.apple.xbs/Sources/UIKit/UIKit-3512.29.5/UITableView.m:1720
2015-12-14 09:29:04.907 Unirenter[552:178776] *** 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 (1) must be
equal to the number of rows contained in that section before the
update (1), 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: (0x220e185b 0x337a2dff 0x220e1731 0x22e72ddb 0x26408269 0x264218c9 0x264217a3 0x8ab6b 0x26555d97
0x26692ba5 0x2624d5e1 0x2624d571 0x26235487 0x2624cec1 0x26206fe7
0x26245c89 0x2624543b 0x262162f1 0x26214937 0x220a47c7 0x220a43b7
0x220a271f 0x21ff50d9 0x21ff4ecd 0x2b36aaf9 0x2627e2dd 0x8f031
0x33ef0873) libc++abi.dylib: terminating with uncaught exception of
type NSException
here a code of deleting
UITableViewRowAction *deleteAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleNormal title:#"Delete" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath){
if (tableView == self.tableView) {
[self deleteMessage:[_id_message objectAtIndex:indexPath.row]];
[_id_message removeObjectAtIndex:indexPath.row];//or something similar to this based on your data source array structure
[self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
}
else
{
NSLog(#"Удаляем id -%d ",[self TitleWithId:[_filteredCandyArray objectAtIndex:indexPath.row]]);
// [_id_message removeObjectAtIndex:[self TitleWithId:[_filteredCandyArray objectAtIndex:indexPath.row]]];
[self.searchDisplayController.searchResultsTableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
}
This code is in a method tableView editActionsForRowAtIndexPath
I understood what business. In the simple table I deleted at first an element and then updated and in the retrieval isn't present. I added a method [_filteredCandyArray removeObjectAtIndex:indexPath.row]; and everything earned
You delete the item from it's data source you send deleteRowsAtIndexPaths:withRowAnimation: to it and it should work fine. The same rules apply as to any tableView, if you modify the data source and want to incrementally update the table view make sure you keep the changes consistent between the data source and the table structure. Thnx
Related
I am trying to store indexPath in NSMutableArray
[checkBoxIndexArray addObject:[NSIndexPath indexPathForRow:indexPath.row inSection:?]];
- (void)reloadItemsAtIndexPaths:(NSArray<NSIndexPath *> *)indexPaths
{
cell.checkBox.image = [UIImage imageNamed:#"check"];
[self.collectionView insertItemsAtIndexPaths:checkBoxIndexArray];
}
but i don't know on what value shall i put for inSection. I tried entering 0,1 but still it's not working. I am getting following error
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid update: invalid number of items in section 0. The number of items contained in an existing section after the update (2) must be equal to the number of items contained in that section before the update (2), plus or minus the number of items inserted or deleted from that section (1 inserted, 0 deleted) and plus or minus the number of items moved into or out of that section (0 moved in, 0 moved out).
i am getting this error for following code
[self.collectionView insertItemsAtIndexPaths:checkBoxIndexArray];
Please tell me what value shall i put for inSection.
you should use
[checkBoxIndexArray addObject: indexPath];
NSIndexPath *indexPath=[Your_Table_Name indexPathForSelectedRow];
[checkBoxIndexArray addObject: indexPath];
Doing
[checkBoxIndexArray addObject:[NSIndexPath indexPathForRow:indexPath.row inSection:?]]
is same as doing this
[checkBoxIndexArray addObject:[NSIndexPath indexPathForRow:indexPath.row inSection:indexPath.section]]
OR Doing this
[checkBoxIndexArray addObject:indexPath]
Add the indexPath directly, and later on access the rows or section values as you please.
I am trying to insert and delete datas in core data. But, while updating that in my tableview I am facing error. Insert working fine. While deleting , facing some issue. Issue is below:
Error:
*** Assertion failure in -[UITableView _endCellAnimationsWithContext:], /SourceCache/UIKit_Sim/UIKit-3347.44.2/UITableView.m:1623
2015-11-24 16:21:18.775 datasApp[1898:91463] CoreData: error: Serious application error. Exception was caught during Core Data change processing. This is usually a bug within an observer of NSManagedObjectContextObjectsDidChangeNotification. Invalid update: invalid number of rows in section 0. The number of rows contained in an existing section after the update (1) must be equal to the number of rows contained in that section before the update (3), 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). with userInfo (null)
2015-11-24 16:21:18.801 datasApp[1898:91463] *** 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 (1) must be equal to the number of rows contained in that section before the update (3), 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).'
***
CODING:
- (void)controller:(NSFetchedResultsController *)controller didChangeObject:(id)anObject
atIndexPath:(NSIndexPath *)indexPath forChangeType:(NSFetchedResultsChangeType)type
newIndexPath:(NSIndexPath *)newIndexPath
{
UITableView *tableView = self.tableView;
switch(type) {
case NSFetchedResultsChangeInsert:
NSLog(#"Insrt_before_tblNum_Row---> %ld",(long)[tableView numberOfRowsInSection:newIndexPath.section]);
[tableView insertRowsAtIndexPaths:#[newIndexPath] withRowAnimation:UITableViewRowAnimationFade];
NSLog(#"Insrt_aftr_tblNum_Row---> %ld",(long)[tableView numberOfRowsInSection:newIndexPath.section]);
break;
case NSFetchedResultsChangeDelete:
//THIS LINE WORKING - TABLEVIEW HAVING 4 ROWS
NSLog(#"delete_before_tblNum_Row---> %ld",(long)[tableView numberOfRowsInSection:newIndexPath.section]);
//GETTING CRASH IN THIS
[tableView deleteRowsAtIndexPaths:#[indexPath] withRowAnimation:UITableViewRowAnimationFade]; LINE
NSLog(#"delete_aftr_tblNum_Row---> %ld",(long)[tableView numberOfRowsInSection:newIndexPath.section]);
break;
case NSFetchedResultsChangeUpdate:
[self.tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:[indexPath row] inSection:0] atScrollPosition:UITableViewScrollPositionTop animated:YES];
NSLog(#"Update");
break;
case NSFetchedResultsChangeMove:
[tableView deleteRowsAtIndexPaths:#[indexPath] withRowAnimation:UITableViewRowAnimationFade];
[tableView insertRowsAtIndexPaths:#[newIndexPath] withRowAnimation:UITableViewRowAnimationFade];
break;
}
}
Hi the following function doesn´t work for me and i don´t get why....
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
if (editingStyle == UITableViewCellEditingStyleDelete)
{
// Delete the row from the data source
NSString *selectedCategory = [self.daten objectAtIndex:indexPath.row];
[self.daten removeObjectAtIndex:indexPath.row]; //we assume, that mySourceArray is a NSMutableArray we use as our data source
[self.tableView beginUpdates];
[self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
[self.tableView endUpdates];
// ...
}
}
I don´t have any Sections...I always get that exception:
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 (19) must be equal to the number of rows contained in that section before the update (19), 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:
(0x342692a3 0x33a3b97f 0x3426915d 0x3922e2af 0x36dd5b83 0x5453d 0x36f6b5d9 0x36e8c0ad 0x36e8c05f 0x36e8c03d 0x36e8b8f3 0x36e8c0ad 0x36e8c05f 0x36e8c03d 0x36e8b8f3 0x36e8bde9 0x36db45f9 0x36da1809 0x36da1123 0x34f195a3 0x34f191d3 0x3423e173 0x3423e117 0x3423cf99 0x341afebd 0x341afd49 0x34f182eb 0x36df5301 0x24343 0x38e34b20)
libc++abi.dylib: terminate called throwing an exception
You need to update your number of rows in numberOfRowsInSection: method. As i can see, you need to return your [self.daten count] in this method.
As its told, the system checks this number before/after update/delete to keep data integrity.
You always have a section :)
Implement it like this:
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [self.daten count];
}
Also, remember that you need to set both UITableViewDelegate and UITableViewDataSource to self.
OK, the problem is: NSMutableArray's removeObjectAtIndex: method does not resize it. So you have to handle it by yourself. Create new array with right capacity and move the rest of elements to it. You can google how to resize NSMutableArray.
Getting the following error when trying to delete a row from a tableview hooked to a fetched results controller:
* Assertion failure in -[UITableView _endCellAnimationsWithContext:], /SourceCache/UIKit_Sim/UIKit-1914.84/UITableView.m:1037
2012-07-12 13:11:19.921 Chef[28843:12203] * 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 (20) must be equal to the number of rows contained in that section before the update (20), 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).'
My code is below.
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
if (editingStyle == UITableViewCellEditingStyleDelete) {
// Delete the record from the DB
RecipeCategory *objectToBeDeleted = [self.fetchedResultsController objectAtIndexPath:indexPath];
[self.context deleteObject:objectToBeDeleted];
// Delete the row from the data source
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
}
else if (editingStyle == UITableViewCellEditingStyleInsert) {
// Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
}
}
Using a fetch request count, and the method - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section, I have tried logging the number of DB records, and the number of rows in the table before and after the line [self.context deleteObject:objectToBeDeleted];, and they both decrease from 20 to 19.
Please help!
Edit: PS the error occurs at the deleteRowsAtIndexPath method.
It turns out that the line of code below was surplus to requirements. I guess the NSFetchedResultsController handles that as well. I also had to implement the delegate methods for NSFetchedResultsController.
// Delete the row from the data source
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
I'm using the code below to refresh a tableview which I just added a row into. The code works for adding a row to the table if there is at least 1 row already in the table. However, it crashes if it was initially an empty table.
NSArray *indexPaths = [NSArray arrayWithObjects: [NSIndexPath indexPathForRow:[commentsArray count] inSection:0], nil];
[commentsTableView beginUpdates];
[commentsArray addObject:newestEntry];
[commentsTableView insertRowsAtIndexPaths:indexPaths withRowAnimation:UITableViewRowAnimationBottom];
[commentsTableView endUpdates];
[commentsTableView scrollToBottom:YES];
The crash response I get is:
*** 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 (0) must be equal to the number of rows contained in that section before the update (0), plus or minus the number of rows inserted or deleted from that section (1 inserted, 0 deleted).'
Can someone help me?
Well, the error is telling you the when UIKit calls tableView:numberOfRowsInSection is returning 0 both before and after your updates. So either you have an error in that method or in your update. You said in comment to a previous answer that your tableView:numberOfRowsInSection is correct, then it must be the update. If commentsArray is nil in the first update for some reason that might explain things. Perhaps try the following:
NSAssert(commentsArray, #"commentsArray is nil");
[commentsArray addObject:newestEntry];
The assert will be ignored in a release build, so use a debug build.
Just make sure the array which you are using to update is the same as Array which you are using while reloading the Table.
// Customize the number of rows in the table view.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [commentsArray count];
}
If this couldn't solve your problem, please put some code over here.