I know this has been asked before 50 times but I have looked through all the other answers and didn't find anything that could fix my issue.
Anyway this is my code:
NSMutableArray *cellIndicesToBeDeleted = [[NSMutableArray alloc] init];
for (int i = 0; i < [thetableView numberOfRowsInSection:0]; i++) {
NSIndexPath *p = [NSIndexPath indexPathForRow:i inSection:0];
if ([[thetableView cellForRowAtIndexPath:p] accessoryType] == UITableViewCellAccessoryCheckmark) {
[cellIndicesToBeDeleted addObject:p];
[self.cellArray removeObjectAtIndex:i];
}
}
[thetableView deleteRowsAtIndexPaths:cellIndicesToBeDeleted withRowAnimation:UITableViewRowAnimationLeft];
[cellIndicesToBeDeleted release];
And when I execute this code I get this crash log:
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).'
Does anyone see what I am doing wrong?
Newish code:
NSMutableIndexSet *mutableIndexSet = [[NSMutableIndexSet alloc] init];
NSMutableArray *cellIndicesToBeDeleted = [[NSMutableArray alloc] init];
for (int i = 0; i < [thetableView numberOfRowsInSection:0]; i++) {
NSIndexPath *p = [NSIndexPath indexPathForRow:i inSection:0];
if ([[thetableView cellForRowAtIndexPath:p] accessoryType] == UITableViewCellAccessoryCheckmark) {
[cellIndicesToBeDeleted addObject:p];
[mutableIndexSet addIndex:p.row];
}
}
[self.cellArray removeObjectsAtIndexes:mutableIndexSet];
[thetableView deleteRowsAtIndexPaths:cellIndicesToBeDeleted withRowAnimation:UITableViewRowAnimationLeft];
[cellIndicesToBeDeleted release];
[mutableIndexSet release];
I figured it out it had to do with the numberOfRowsInSection. I wasn't updating my nsuserdefaults with the updated datasource so I did that now and it works perfectly. Here is my updated code by the way:
//Code to delete rows
NSMutableIndexSet *mutableIndexSet = [[NSMutableIndexSet alloc] init];
NSMutableArray *cellIndicesToBeDeleted = [[NSMutableArray alloc] init];
for (int i = [thetableView numberOfRowsInSection:0] - 1; i >= 0; i--) {
NSIndexPath *p = [NSIndexPath indexPathForRow:i inSection:0];
if ([[thetableView cellForRowAtIndexPath:p] accessoryType] == UITableViewCellAccessoryCheckmark) {
[cellIndicesToBeDeleted addObject:p];
[mutableIndexSet addIndex:p.row];
}
}
[self.cellArray removeObjectsAtIndexes:mutableIndexSet];
[[NSUserDefaults standardUserDefaults] setObject:self.cellArray forKey:#"cellArray"];
[thetableView deleteRowsAtIndexPaths:cellIndicesToBeDeleted withRowAnimation:UITableViewRowAnimationLeft];
[cellIndicesToBeDeleted release];
[mutableIndexSet release];
You need to add the following before and after you remove the row:
[theTableView beginUpdates];
// your code goes here
[theTableView endUpdates];
Related
Currently I have a UITableView which is expands and collapses with the current code.
- (BOOL)tableView:(UITableView *)tableView canCollapseSection:(NSInteger)section{
if (section>=0) return YES;
return NO;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
NSInteger numberofRows = 0;
numberofRows = nameArray.count;
if (numberofRows != 0){
self.mainTableView.hidden = false;
}
return numberofRows;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
if ([self tableView:tableView canCollapseSection:indexPath.section])
{
if (!indexPath.row)
{
// only first row toggles exapand/collapse
[tableView deselectRowAtIndexPath:indexPath animated:YES];
NSInteger section = indexPath.section;
BOOL currentlyExpanded = [expandedSections containsIndex:section];
NSInteger rows;
NSMutableArray *tmpArray = [NSMutableArray array];
if (currentlyExpanded)
{
rows = [self tableView:tableView numberOfRowsInSection:section];
[expandedSections removeIndex:section];
}
else
{
[expandedSections addIndex:section];
rows = [self tableView:tableView numberOfRowsInSection:section];
}
for (int i=1; i<rows; i++)
{
NSIndexPath *tmpIndexPath = [NSIndexPath indexPathForRow:i
inSection:section];
[tmpArray addObject:tmpIndexPath];
}
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
if (currentlyExpanded)
{
[tableView deleteRowsAtIndexPaths:tmpArray
withRowAnimation:UITableViewRowAnimationTop];
cell.accessoryView = [ALCustomColoredAccessory accessoryWithColor:[UIColor grayColor] type:ALCustomColoredAccessoryTypeDown];
}
else
{
[tableView insertRowsAtIndexPaths:tmpArray
withRowAnimation:UITableViewRowAnimationTop];
cell.accessoryView = [ALCustomColoredAccessory accessoryWithColor:[UIColor grayColor] type:ALCustomColoredAccessoryTypeUp];
}
}
else {
NSLog(#"Selected Section is %ld and subrow is %ld ",(long)indexPath.section ,(long)indexPath.row);
}
}
}
This works really well and upon selection of a UITableViews section the rows are expanded and populated with the correct data and when the same section is selected the rows are removed and appear collapsed.
However what i want to do is somehow automatically collapse the previous selected section and remove the rows within that previous section when the user selects a new indexpath.section.
I have tried storing the selected section index path to an array removing rows based on this value but I think I'm going about it the wrong way as I get assertion failures.
So my question is as follows :-
How can i automatically collapse (remove rows) from a uitableviews section upon selection of another section
Thanks for your help in advance
Thomas
i have faced this issue when i was writting code for my app and i founded this post that had no any single comment or answer...
You can use this code that i was written for me to colapse previous expanded rows of section when i clicked on other section and expand rows of that section, this code working for me try it...
`
- (BOOL)tableView:(UITableView *)tableView canCollapseSection:(NSInteger)section
{
if (section>=0) return YES;
return NO;
}
static NSInteger Value=0;
static NSInteger Value2=0;
static CFIndex indexPre=0;
static NSMutableArray *preArray;
static NSIndexPath *path;
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if ([self tableView:tableView canCollapseSection:indexPath.section])
{
if (!indexPath.row)
{
TableViewCell *cell = (TableViewCell *)[tableView cellForRowAtIndexPath:indexPath];
cell.hideButton.hidden=NO;
[tableView deselectRowAtIndexPath:indexPath animated:YES];
NSUInteger index=[expandedSections firstIndex];
if ([expandedSections indexGreaterThanIndex:index])
{
NSLog(#"%lu hhhwww", index);
}
NSInteger section = indexPath.section;
static NSInteger rows;
static NSInteger PreRows;
NSLog(#"%lu MY INDEXES1",(unsigned long)[expandedSections count]);
NSMutableArray *tmpArray = [NSMutableArray array];
preArray = [NSMutableArray array];
BOOL currentlyExpanded = [expandedSections containsIndex:section];
if (currentlyExpanded)
{
rows = [self tableView:tableView numberOfRowsInSection:section];
[expandedSections removeIndex:section];
Value=0;
Value2=0;
cell.hideButton.hidden=YES;
}
else
{
if (Value==0)
{
[expandedSections addIndex:section];
rows = [self tableView:tableView numberOfRowsInSection:section];
PreRows = [self tableView:tableView numberOfRowsInSection:section];
indexPre=indexPath.section;
Value=1;
}
else if (Value==1)
{
Value2=1;
NSLog(#"indexPre == %ld %# my indexxxxx", indexPre, expandedSections);
[expandedSections removeIndex:indexPre];
NSLog(#"indexPre == %ld %# my indexxxxx", indexPre, expandedSections);
[self.tableView reloadData];
[expandedSections addIndex:section];
NSLog(#"indexPre == %ld %# my indexxxxx", indexPre, expandedSections);
rows=[self tableView:tableView numberOfRowsInSection:section];
}
}
NSLog(#"%# MY INDEXES",expandedSections);
if (Value2==1)
{
for (int i=1; i<PreRows; i++)
{
NSIndexPath *tmpIndexPath = [NSIndexPath indexPathForRow:i
inSection:indexPre];
[preArray addObject:tmpIndexPath];
}
NSLog(#"my arrray %#", preArray);
for (int i=1; i<rows; i++)
{
NSIndexPath *tmpIndexPath = [NSIndexPath indexPathForRow:i
inSection:section];
[tmpArray addObject:tmpIndexPath];
}
NSLog(#"my arrray tmparray%#", preArray);
}
else
{
for (int i=1; i<rows; i++)
{
NSIndexPath *tmpIndexPath = [NSIndexPath indexPathForRow:i
inSection:section];
[tmpArray addObject:tmpIndexPath];
}
}
if (currentlyExpanded )
{
[tableView deleteRowsAtIndexPaths:tmpArray
withRowAnimation:NO];
cell.accessoryView = [DTCustomColoredAccessory accessoryWithColor:[UIColor grayColor] type:DTCustomColoredAccessoryTypeDown];
}
else if(Value==1)
{
if (Value2==1)
{
[tableView beginUpdates];
[tableView insertRowsAtIndexPaths:tmpArray
withRowAnimation:NO];
cell.accessoryView = [DTCustomColoredAccessory accessoryWithColor:[UIColor grayColor] type:DTCustomColoredAccessoryTypeUp];
[tableView endUpdates];
[tableView beginUpdates];
[tableView endUpdates];
indexPre=indexPath.section;
}
else
{
[tableView insertRowsAtIndexPaths:tmpArray
withRowAnimation:UITableViewRowAnimationTop];
cell.accessoryView = [DTCustomColoredAccessory accessoryWithColor:[UIColor grayColor] type:DTCustomColoredAccessoryTypeUp];
}
}
}
}
}
`
I am inserting and removing rows at random from a tableview. However, if the rows I want to remove are not in view, they are not actually removed in the UI when the given row does come back to view.
If I add and remove the rows only on visible rows, it works just fine. What could be causing this problem?
- (void)sectionHeaderView:(BaseSectionHeaderView *)sectionHeaderView sectionOpened:(NSInteger)sectionOpened {
LogInfo(#"opening section:%ld",sectionOpened);
[_dataSource setSectionAtIndex:sectionOpened Open:YES];
/*
Create an array containing the index paths of the rows to insert: These correspond to the rows for each quotation in the current section.
*/
NSInteger countOfRowsToInsert = [_dataSource tableView:_tableView numberOfRowsInSection:sectionOpened];
NSMutableArray *indexPathsToInsert = [[NSMutableArray alloc] init];
for (NSInteger i = 0; i < countOfRowsToInsert; i++) {
[indexPathsToInsert addObject:[NSIndexPath indexPathForRow:i inSection:sectionOpened]];
}
/*
Create an array containing the index paths of the rows to delete: These correspond to the rows for each quotation in the previously-open section, if there was one.
*/
NSMutableArray *indexPathsToDelete = [[NSMutableArray alloc] init];
if (self.openSection.openSectionHeaderView != nil) {
[_openSection.openSectionHeaderView toggleOpenWithUserAction:NO];
// NSInteger countOfRowsToDelete = [_purchaseInvoiceListTable.tableView numberOfRowsInSection:self.openSection.openSectionIndex];
NSInteger countOfRowsToDelete = [_dataSource tableView:_tableView numberOfRowsInSection:self.openSection.openSectionIndex];
[_dataSource setSectionAtIndex:self.openSection.openSectionIndex Open:NO];
for (NSInteger i = 0; i < countOfRowsToDelete; i++) {
[indexPathsToDelete addObject:[NSIndexPath indexPathForRow:i inSection:self.openSection.openSectionIndex]];
}
}
// style the animation so that there's a smooth flow in either direction
UITableViewRowAnimation insertAnimation;
UITableViewRowAnimation deleteAnimation;
if (self.openSection.openSectionHeaderView == nil || sectionOpened < self.openSection.openSectionIndex) {
insertAnimation = UITableViewRowAnimationTop;
deleteAnimation = UITableViewRowAnimationBottom;
}
else {
insertAnimation = UITableViewRowAnimationBottom;
deleteAnimation = UITableViewRowAnimationTop;
}
// apply the updates
[_tableView beginUpdates];
[_tableView insertRowsAtIndexPaths:indexPathsToInsert withRowAnimation:insertAnimation];
[_tableView deleteRowsAtIndexPaths:indexPathsToDelete withRowAnimation:deleteAnimation];
[_tableView endUpdates];
self.openSection.openSectionIndex = sectionOpened;
self.openSection.openSectionHeaderView = sectionHeaderView;
self.openSection.sectionHeight = [NSNumber numberWithFloat:sectionHeaderView.frame.size.height];
LogInfo(#"sectionOpened:%ld",sectionOpened);
}
i think you should reload the table view by this...
[tableView reloadData];
and if from this it will not give the expected result then remove the object from array that fill the table view's row. i think this will definitely work...
tell me is it working or not...
I want to expand/collapse table view sections.I googled and found a code and its working fine.but the problem is the previously opened section is not closed when a new section is opened.Thanks
- (void)sectionHeaderTapped:(UITapGestureRecognizer *)gestureRecognizer{
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:gestureRecognizer.view.tag];
if (indexPath.row == 0) {
BOOL collapsed = [[arrayForBool objectAtIndex:indexPath.section] boolValue];
collapsed = !collapsed;
[arrayForBool replaceObjectAtIndex:indexPath.section withObject:[NSNumber numberWithBool:collapsed]];
//reload specific section animated
NSRange range = NSMakeRange(indexPath.section, 1);
NSIndexSet *sectionToReload = [NSIndexSet indexSetWithIndexesInRange:range];
[self.aTableView reloadSections:sectionToReload withRowAnimation:UITableViewRowAnimationFade];
}
}
I tried the following code which is working but the animation is not cool as all the sections are reloading.
NSMutableArray *isSectionTouched =[[NSMutableArray alloc]initWithCapacity:arrayForBool.count];
isSectionTouched=[arrayForBool mutableCopy];
for(int i = 1; i <[arrayForBool count] ; i ++){
if(i != gestureRecognizer.view.tag){
[isSectionTouched replaceObjectAtIndex:i withObject:[NSNumber numberWithBool:NO]];
}else{
if ([[isSectionTouched objectAtIndex:gestureRecognizer.view.tag]boolValue]==YES) {
[isSectionTouched replaceObjectAtIndex:gestureRecognizer.view.tag withObject:[NSNumber numberWithBool:NO]];
}else if ([[isSectionTouched objectAtIndex:gestureRecognizer.view.tag]boolValue]==NO){
[isSectionTouched replaceObjectAtIndex:gestureRecognizer.view.tag withObject:[NSNumber numberWithBool:YES]];
}
}
}
arrayForBool=isSectionTouched;
NSRange range = NSMakeRange(1,arrayForBool.count - 1);
NSIndexSet *sectionToReload = [NSIndexSet indexSetWithIndexesInRange:range];
[self.tableView reloadSections:sectionToReload withRowAnimation:UITableViewRowAnimationFade];
Just before you replace the selected index path, iterate over arrayForBool and set each item to NO. You could hold a property to store the currently open section index but unless you have hundreds of sections it isn't worth it.
I have a problem with my UITableView where deleting the last row in the section terminates the app with an NSInternalInconsistencyException:
*** 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).'
My UITableView is populated with MPMediaItems from an MPMediaItemCollection (self.detailCollection). When the last one gets deleted I want to show a "No results found" label in a blank cell.
Here is my cellForRowAtIndexPath:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
// Configure the cell...
if ([[self.detailCollection items] count] == 0) {
[tableView numberOfRowsInSection:1];
cell.textLabel.text = #"No results found";
//return cell;
} else {
MPMediaItem *song = (MPMediaItem *)[[self.detailCollection items] objectAtIndex:[indexPath row]];
if (song) {
cell.textLabel.text = [song valueForProperty:MPMediaItemPropertyTitle];
MPMediaItemArtwork *art = [song valueForProperty:MPMediaItemPropertyArtwork];
cell.imageView.image = [art imageWithSize:CGSizeMake(64, 64)];
}
}
return cell;
}
Here is my code for deleting the rows:
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
PlaylistData *pData = [PlaylistData getInstance];
NSMutableArray *tempArray = [[self.eventDictionary valueForKey:[NSString stringWithFormat:#"%#", pData.selectedEvent]] mutableCopy];
NSMutableArray *newArray = [[NSMutableArray alloc] init];
if (editingStyle == UITableViewCellEditingStyleDelete) {
[tableView beginUpdates];
// Delete the row from the data source
[tempArray removeObjectAtIndex:indexPath.row];
[self.eventDictionary setValue:tempArray forKey:[NSString stringWithFormat:#"%#", pData.selectedEvent]];
[[NSUserDefaults standardUserDefaults] setValue:self.eventDictionary forKey:#"Playlist Items"];
[[NSUserDefaults standardUserDefaults] synchronize];
if ([tempArray count] == 0) {
[tableView numberOfRowsInSection:1];
}
for (int i=0; i<[tempArray count]; i++) {
NSString *pID = [NSString stringWithFormat:#"%#", [tempArray objectAtIndex:i]];
unsigned long long ullvalue = strtoull([pID UTF8String], NULL, 0);
NSNumber *UniqueID = [NSNumber numberWithUnsignedLongLong:ullvalue];
MPMediaQuery *cellQuery = [[MPMediaQuery alloc] init];
[cellQuery addFilterPredicate:[MPMediaPropertyPredicate predicateWithValue:UniqueID forProperty:MPMediaItemPropertyPersistentID]];
for (MPMediaItem *item in [cellQuery items]) {
[newArray addObject:item];
}
[cellQuery release];
}
if (![newArray count] == 0) {
self.detailCollection = [[MPMediaItemCollection alloc] initWithItems:newArray];
[tableView numberOfRowsInSection:[self.detailCollection count]];
} else {
[tableView numberOfRowsInSection:1];
[tableView reloadData];
}
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
[tableView endUpdates];
}
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
}
}
And here is my numberOfRowsInSection:
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
if ([[self.detailCollection items] count] == 0 || [self.detailCollection items] == nil || [self.detailCollection items] == NULL) {
return 1;
}
return [[self.detailCollection items] count];
}
My question is: Why isn't it creating the "No results found" cell when self.detailCollection is == 0?
I think you want something to the effect of:
[tableView beginUpdates];
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
if ([newArray count] == 0) {
[tableView insertRowsAtIndexPaths:#[[NSIndexPath indexPathForRow:0 inSection:0]] withRowAnimation:UITableViewRowAnimationAutomatic];
}
[tableView endUpdates];
However, a simpler solution would be to just add a label to your table view. Unless there is some specific reason that you need an actual UITableViewCell to display "No results found".
UILabel *label = [[UILabel alloc] init];
CGRect frame = CGRectMake(0.0, 0.0, 320.0, 44.0);
label.frame = frame;
label.text = #"No results found";
[self.tableView addSubview:label];
One solution that I would recommend is to use a table footer view rather than a new cell. Basically, add a footer to your table that is only visible when the cell count is 0.
You can override the method
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
to get a footer.
When deleting and adding objects, check the new count and then adjust the visibility of the footer from there.
You are calling numberOfRowsInSection in a couple of places. You should never be calling it, it's a call back hook that you implement and the system calls.
The cleanest solution to do this would be to set self.tableView.tableFooterView when rows = 0
#interface UITableView : UIScrollView <NSCoding> {
...
#property(nonatomic,retain) UIView *tableFooterView;
// accessory view below content. default is nil. not to be confused with section footer
I have the following code.
NSMutableArray *aList = [[NSMutableArray alloc] init];
for (NSIndexPath *indexPath in tableview1.indexPathsForSelectedRows) {
NSString *r = [NSString stringWithFormat:#"%i",indexPath.row];
[aList addObject:r];
}
So what I get is a list of UITableView rows that are selected. Is there a simple way of getting a list of rows that are NOT selected?
Thank you for your help.
There may be elegant solutions but this will work.
NSMutableArray *allIndexPaths = [#[]mutableCopy];
NSInteger nSections = [self.tableView numberOfSections];
for (int j=0; j<nSections; j++) {
NSInteger nRows = [self.tableView numberOfRowsInSection:j];
for (int i=0; i<nRows; i++) {
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:i inSection:j];
[allIndexPaths addObject:indexPath];
}
}
NSArray *selectedIndexPaths = self.tableView.indexPathsForSelectedRows;
for (NSIndexPath *indexPath in selectedIndexPaths) {
[allIndexPaths removeObject:indexPath];
}
NSArray *unselectedIndexPaths = [NSArray arrayWithArray:allIndexPaths];
EDIT : As per Rikkles suggestion
NSMutableArray *unselectedIndexPaths = [#[]mutableCopy];
NSArray *selectedIndexPaths = self.tableView.indexPathsForSelectedRows;
NSInteger nSections = [self.tableView numberOfSections];
for (int j=0; j<nSections; j++) {
NSInteger nRows = [self.tableView numberOfRowsInSection:j];
for (int i=0; i<nRows; i++) {
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:i inSection:j];
if (![selectedIndexPaths containsObject:indexPath]) {
[unselectedIndexPaths addObject:indexPath];
}
}
}
NSMutableArray *a = [NSMutableArray array]; // that's all unselected indexPaths
NSArray *l = [self.tableView indexPathsForSelectedRows];
NSIndexPath *idx;
for (NSUInteger sec=0; sec<[self.tableView numberOfSections]; sec++) {
for (NSUInteger r=0; r<[self.tableView numberOfRowsInSection:sec]; r++) {
idx = [NSIndexPath indexPathForRow:r inSection:sec];
if(![l containsObject:idx]){
[a addObject:idx];
}
}
}
You can use the numberOfRows return value minus the total selected rows.
I've added several additional lines to Anupdas' code. He certainly deserves the entire credit.
NSMutableArray *allIndexPaths = [#[]mutableCopy];
NSInteger nSections = [tableview1 numberOfSections];
for (int j=0; j < nSections; j++) {
NSInteger nRows = [tableview1 numberOfRowsInSection:j];
for (int i=0; i<nRows; i++) {
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:i inSection:j];
[allIndexPaths addObject:indexPath];
}
}
NSArray *selectedIndexPaths = tableview1.indexPathsForSelectedRows;
for (NSIndexPath *indexPath in selectedIndexPaths) {
[allIndexPaths removeObject:indexPath];
}
NSMutableArray *bList = [[NSMutableArray alloc] init];
for (NSInteger k = 0; k < allIndexPaths.count; k++) {
NSString *r = [NSString stringWithFormat:#"%i",[[allIndexPaths objectAtIndex:k] row]];
[bList addObject:r];
}
NSMutableArray * yourNewArr = [[NSMutableArray alloc ] init];
for(NSUInteger i = 0 ; i < [yourArr count] ; i++){
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:i inSection:0];
NSArray *selIndexs = self.tableView.indexPathsForSelectedRows;
if(![selIndexs containsObject:indexPath]){
[yourNewArr addObject:indexPath];
}
}
NSLog(#"%#", yourNewArr); // this will contain unselected index paths.