There may be elegant solutions, but it 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: according to 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]; } } }
source share