I am adding a filter function to my app, but every time a filter is applied a previously opened cell does not close when I change the filter, is there a way to implement this?
I am currently using:
[self.tableview reloadData];
to reload the table every time the filter is applied
To open and close:
- (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];
NSLog(#"Section:%d", rows);
}
for (int i=1; i<rows; i++)
{
NSIndexPath *tmpIndexPath = [NSIndexPath indexPathForRow:i
inSection:section];
NSLog(#"INDEX: %#", tmpIndexPath);
[tmpArray addObject:tmpIndexPath];
}
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
if (currentlyExpanded)
{
dispatch_async(dispatch_get_main_queue(), ^{
[tableView deleteRowsAtIndexPaths:tmpArray
withRowAnimation:UITableViewRowAnimationTop];
});
}
else
{
dispatch_async(dispatch_get_main_queue(), ^{
[tableView insertRowsAtIndexPaths:tmpArray
withRowAnimation:UITableViewRowAnimationTop];
});
}
}
}
Before tableview reloadData clear the expandedSections array.
[expandedSections removeAllIndexes];
[self.tableView reloadData];
expandedSections Array maintains the status of the expand section details.Due to that its not collapse the view. So clear the array before reload the table view.
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 have an issue where I have a UITableViewController and when the view appears I do some calculations asynchronously which should result in the updating of specific rows in the table.
Inside the viewWillAppear function I calculate the necessary rows that need to be updated as follows:
- (void)reloadPaths:(NSMutableDictionary *)bookingsDict
{
NSMutableArray* indexArray = [NSMutableArray array];
int i = 0;
for (NSString *dateKey in self.eventsToShow) {
NSMutableDictionary *venues = [bookingsDict objectForKey:dateKey];
if (venues) {
int j = 0;
NSArray *events = [self.eventsToShow objectForKey:dateKey];
for (DCTEvent *event in events) {
NSString *venueIdString = [NSString stringWithFormat:#"%#", event.eventVenueId];
if ([venues objectForKey:venueIdString]) {
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:j inSection:i];
[indexArray addObject:indexPath];
}
j++;
}
}
i++;
}
[self.tableView reloadRowsAtIndexPaths:indexArray withRowAnimation:UITableViewRowAnimationFade];
}
However I notice that the cellForRowAtIndexPath function is never called after and the cells do not get updated correctly. Any idea what the issue might be?
EDIT: I just noticed that if I scroll out of the view of the cell that is supposed to get updated then it gets updated when I scroll back into view. Is there no way to have it update while in view?
How about wrap it?
[tableView beginUpdates];
[tableView reloadRowsAtIndexPaths:#[indexPath] withRowAnimation:UITableViewRowAnimationNone];
[tableView endUpdates];
Here are some similar problems I have found.
cellForRowAtIndexPath isn't called after reloadRowsAtIndexPaths
UITableView's reloadRowsAtIndexPaths: (NSArray *) indexPaths failing to cause a reload unless you call it twice?
Hope this helps.
EDIT : I think you are not getting indexPath check section might be constant as you are increasing while each object gets traversed:
- (void)reloadPaths:(NSMutableDictionary *)bookingsDict
{
NSMutableArray* indexArray = [NSMutableArray array];
int i = 0;
for (NSString *dateKey in self.eventsToShow) {
NSMutableDictionary *venues = [bookingsDict objectForKey:dateKey];
if (venues) {
int j = 0;
NSArray *events = [self.eventsToShow objectForKey:dateKey];
for (DCTEvent *event in events) {
NSString *venueIdString = [NSString stringWithFormat:#"%#", event.eventVenueId];
if ([venues objectForKey:venueIdString]) {
//changed here as section might be constant as i think it might be
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:j inSection:0];
[indexArray addObject:indexPath];
}
j++;
}
}
i++;
}
[self.tableView beginUpdates];
[self.tableView reloadRowsAtIndexPaths:indexArray withRowAnimation:UITableViewRowAnimationFade];
[self.tableView endUpdates];
}
Try this :
//your code here
[self.tableView beginUpdates];
[self.tableView reloadRowsAtIndexPaths:indexArray withRowAnimation:UITableViewRowAnimationFade];
[self.tableView endUpdates];
For me pushing my reload code to the main queue solved the problem
DispatchQueue.main.async {
self.tableView.reloadRows(at: [indexPath], with: .automatic)
}
i'm new to iOS programming, i want to save the text entered inside a text box placed inside a dynamic table cell where the table cell contents are like accordion.
in view controller table view with 3 dynamic prototype cells are used each cell is named as header,regular and selected respectively and in view controller i used the following code
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell * cell = nil;
switch (indexPath.row) {
case 0:
{
cell = [tableView dequeueReusableCellWithIdentifier:#"Header"];
}
break;
default:
{
NSArray * innerData = [self.data objectAtIndex:indexPath.row - 1];
if(indexPath.row == self.selectedIndex)
{
SelectedCell * tmpCell = (SelectedCell *)[tableView dequeueReusableCellWithIdentifier:#"Selected"];
[tmpCell.label1 setText:[NSString stringWithFormat:#"%#", [innerData objectAtIndex:0]]];
cell = tmpCell;
tmpCell.textLabel.numberOfLines=2;
}
else
{
RegularCell * tmpCell = (RegularCell *)[tableView dequeueReusableCellWithIdentifier:#"Regular"];
[tmpCell.label1 setText:[NSString stringWithFormat:#"%#", [innerData objectAtIndex:0]]];
cell = tmpCell;
tmpCell.textLabel.numberOfLines=2;
}
}
break;
}
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
if(indexPath.row == 0)
return;
if(indexPath.row != self.selectedIndex && self.selectedIndex > 0)
{
// Selected different row while there is another selected row
int oldIndex = self.selectedIndex;
self.selectedIndex = indexPath.row;
NSArray * innerData = [self.data objectAtIndex:oldIndex - 1];
[self.data removeObjectAtIndex:oldIndex - 1];
NSIndexPath * deselectedIndexPath = [NSIndexPath indexPathForRow:oldIndex inSection:0];
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:deselectedIndexPath] withRowAnimation:UITableViewRowAnimationNone];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.0 * NSEC_PER_SEC),
dispatch_get_main_queue(),
^{
[self.data insertObject:innerData atIndex:deselectedIndexPath.row - 1];
[tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:deselectedIndexPath] withRowAnimation:UITableViewRowAnimationTop];
[tableView reloadData];
NSArray * innerData = [self.data objectAtIndex:indexPath.row - 1];
[self.data removeObjectAtIndex:indexPath.row - 1];
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationNone];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.2 * NSEC_PER_SEC),
dispatch_get_main_queue(),
^{
[self.data insertObject:innerData atIndex:indexPath.row - 1];
[tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationTop];
[tableView reloadData];
});
});
}
else
{
if(indexPath.row == self.selectedIndex) // selected active row -> close
self.selectedIndex = -1;
else // selected inactive row -> open
self.selectedIndex = indexPath.row;
NSArray * innerData = [self.data objectAtIndex:indexPath.row - 1];
[self.data removeObjectAtIndex:indexPath.row - 1];
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationNone];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.2 * NSEC_PER_SEC),
dispatch_get_main_queue(),
^{
[self.data insertObject:innerData atIndex:indexPath.row - 1];
[tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationTop];
[tableView reloadData];
});
}
}
now i want to store the text entered in each field specific to that cell i searched a lot of tutorials but i could not find it
please provide me with suitable solution ASAP
thanks in advance
My current tableview expands the cells on click, example:
Parent 0
-Child 1
-Child 2
-Child 3
What I'm struggling to do is, when I expand a cell all the others will close, I'm trying to make sure only one cell Is open at the time. Can you guys give any ideas on how to do it?
Current code for expanding the cell:
- (void)tableView:(UITableView *)tableView1 didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.section==0) {
if([d valueForKey:#"produtos"]) {
NSArray *ar=[d valueForKey:#"produtos"];
BOOL isAlreadyInserted=NO;
for(NSDictionary *dInner in ar ){
NSInteger index=[self.firstForTable indexOfObjectIdenticalTo:dInner];
isAlreadyInserted=(index>0 && index!=NSIntegerMax);
if(isAlreadyInserted) break;
}
if(isAlreadyInserted) {
[self miniMizeFirstsRows:ar];
} else {
NSUInteger count=indexPath.row+1;
NSMutableArray *arCells=[NSMutableArray array];
for(NSDictionary *dInner in ar ) {
[arCells addObject:[NSIndexPath indexPathForRow:count inSection:0]];
[self.firstForTable insertObject:dInner atIndex:count++];
}
[tableView1 beginUpdates];
[tableView1 insertRowsAtIndexPaths:arCells withRowAnimation:UITableViewRowAnimationNone];
[tableView1 endUpdates];
[tableView1 scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionTop animated:YES];
}
}else{
NSLog(#"child %# %#|",[item valueForKey:#"nome"],[item valueForKey:#"produtos"]);
}
}
Current code for minimizing the cell:
-(void)miniMizeFirstsRows:(NSArray*)ar{
NSLog(#"miniMizeFirstsRows");
for(NSDictionary *dInner in ar ) {
NSUInteger indexToRemove=[self.firstForTable indexOfObjectIdenticalTo:dInner];
NSArray *arInner=[dInner valueForKey:#"produtos"];
if(arInner && [arInner count]>0){
[self miniMizeFirstsRows:arInner];
}
if([self.firstForTable indexOfObjectIdenticalTo:dInner]!=NSNotFound) {
[self.firstForTable removeObjectIdenticalTo:dInner];
[tableView beginUpdates];
[self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:
[NSIndexPath indexPathForRow:indexToRemove inSection:0]
]
withRowAnimation:UITableViewRowAnimationFade];
[tableView endUpdates];
}
}
}
Thanks in Advance.
EDIT still Can't make it work
What I have, by using the help from Marco answer:
NSLog(#"indexPath1 = %i",selectedRow);
NSDictionary *d=[self.firstForTable objectAtIndex:indexPath.row];
if([d valueForKey:#"Objects"]) {
NSArray *ar=[d valueForKey:#"Objects"];
NSUInteger count=indexPath.row +1;
NSMutableArray *arCells=[NSMutableArray array];
for(NSDictionary *dInner in ar ) {
[arCells addObject:[NSIndexPath indexPathForRow:count inSection:0]];
[self.firstForTable insertObject:dInner atIndex:count++];
}
[tableView insertRowsAtIndexPaths:arCells withRowAnimation:UITableViewRowAnimationLeft];
// }
}else
{
NSLog(#"Leave Element:::%# %#|",[d valueForKey:#"name"],[d valueForKey:#"book"]);
}
// The user is selecting the cell which is currently expanded
// we want to minimize it back
if (selectedRow == row)
{
NSLog(#"selectedRow2 = %i",selectedRow);
NSDictionary *d=[self.firstForTable objectAtIndex:selectedRow];
if([d valueForKey:#"Objects"]) {
NSArray *ar=[d valueForKey:#"Objects"];
[self miniMizeFirstsRows:ar];
}
selectedRow = -1;
return;
}
// First we check if a cell is already expanded.
// If it is we want to minimize make sure it is reloaded to minimize it back
if (selectedRow >= 0)
{
NSLog(#"selectedRow3 = %i",selectedRow);
NSDictionary *d=[self.firstForTable objectAtIndex:selectedRow];
if([d valueForKey:#"Objects"]) {
NSArray *ar=[d valueForKey:#"Objects"];
[self miniMizeFirstsRows:ar];
}
selectedRow = row;
}
// Finally set the selected index to the new selection and reload it to expan
selectedRow = row;
[tableView beginUpdates]; [tableView endUpdates];
}
Some more help please :)
One thing missing from Marco's answer is the implementation of "heightForRowAtIndexPath" Delegate method.
So these are the steps you need to follow:
Create a variable to record the selected row number
Update that variable when a row is selected (in "didSelectRowAtIndexPath" delegate method) and call tableView's beginUpdates & endUpdates methods.
Return bigger height when indexPath.row == selectedRow, else return normal height.
You need an instance variable to track your selected cell.
NOTE: The code below is not meant to replace your tableview data source and delegate methods, but as an example to track a selected cell:
Add an NSInteger selectedRow instance variable to your view controller.
In viewDidLoad, initialize selectedRow to indicate no cell will be expanded:
- (void)viewDidLoad
{
[super viewDidLoad];
// Set set our selectedRow to -1 to indicate no cell will be expanded
selectedRow = -1;
}
In tableView:didSelectRowAtIndexPath::
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSInteger row = indexPath.row;
// The user is selecting the cell which is currently expanded
// we want to minimize it back
if (selectedRow == row)
{
selectedRow = -1;
[tableView beginUpdates]; [tableView endUpdates];
return;
}
// First we check if a cell is already expanded.
// If it is we want to minimize make sure it is reloaded to minimize it back
if (selectedRow >= 0)
{
selectedRow = row;
}
// Finally set the selected index to the new selection and reload it to expand
selectedRow = row;
[tableView beginUpdates]; [tableView endUpdates];
}
I have a UITableView containing list of images, each row contains 4 UITableViewCell,
the user can select multiple images (selection is by hiding and showing an overlay image on the cell)
what i want to do is when user click delete button is to remove the selected image from my table.
Here is some of the code:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *CellIdentifier = #"Cell";
ThumbnailImageCell *cell = (ThumbnailImageCell *)[tableView dequeueReusableCellWithIdentifier:#"Cell"];
if (cell == nil)
{
cell = [[[ThumbnailImageCell alloc] initWithManagedImages:[self imagesForIndexPath:indexPath] reuseIdentifier:CellIdentifier] autorelease];
}
else
{
[cell setImages:[self imagesForIndexPath:indexPath]];
}
return cell;}
-(NSArray*)imagesForIndexPath:(NSIndexPath*)_indexPath {
int index = (_indexPath.row*4);
int maxIndex = (_indexPath.row*4+3);
if(maxIndex < [self.imagesArray count]) {
return [NSArray arrayWithObjects:[self.imagesArray objectAtIndex:index],
[self.imagesArray objectAtIndex:index+1],
[self.imagesArray objectAtIndex:index+2],
[self.imagesArray objectAtIndex:index+3],
nil];
}
else if(maxIndex-1 < [self.imagesArray count]) {
return [NSArray arrayWithObjects:[self.imagesArray objectAtIndex:index],
[self.imagesArray objectAtIndex:index+1],
[self.imagesArray objectAtIndex:index+2],
nil];
}
else if(maxIndex-2 < [self.imagesArray count]) {
return [NSArray arrayWithObjects:[self.imagesArray objectAtIndex:index],
[self.imagesArray objectAtIndex:index+1],
nil];
}
else if(maxIndex-3 < [self.imagesArray count]) {
return [NSArray arrayWithObject:[self.imagesArray objectAtIndex:index]];
}
return nil;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return ceil([self.imagesArray count] / 4.0);
}
What I tried to do is the following but without any success till now
-(void)finishDeleting{
int countOfDeletedThread;
[self setEditing:YES animated:YES];
[self.tableView beginUpdates];
NSMutableIndexSet *mutableIndexSet = [[NSMutableIndexSet alloc] init];
NSMutableArray *indexToDelete = [[NSMutableArray alloc] init];
NSIndexPath *indexPath ;
for(ThumbnailImage *thumbnailImage in self.imagesArray)
{
if([thumbnailImage selected])
{
countOfDeletedThread = countOfDeletedThread+1;
indexPath = [NSIndexPath indexPathForRow:countOfDeletedThread inSection:0];
[indexToDelete addObject:indexPath];
[mutableIndexSet addIndex:indexPath.row];
}
}
[self.imagesArray removeObjectsAtIndexes:mutableIndexSet];
[self.tableView deleteRowsAtIndexPaths:indexToDelete withRowAnimation:UITableViewRowAnimationFade];
[indexToDelete release];
[mutableIndexSet release];
[self.tableView endUpdates];
[self.tableView setEditing:NO animated:YES];
[self.tableView reloadData];
[CATransaction flush];}
Any help please? I am stuck for 2 days and don't know what to do.
Thank you.
If I understand it correctly, you have 4 UIImageViews per table row, not
4 UITableViewCells. That means if you delete a subset of the images, the remaining
images will "reflow" across all rows. Therefore it does not make sense to use
beginUpdates/deleteRowsAtIndexPaths/endUpdates. You probably should just
remove the selected images from the data source array self.imagesArray,
call [self.tableView reloadData].
Removing the selected images from the array can be slightly simplified to
NSIndexSet *indexSet = [self.imagesArray indexesOfObjectsPassingTest:^BOOL(ThumbnailImage *thumbnailImage, NSUInteger idx, BOOL *stop) {
return [thumbnailImage selected];
}];
[self.imagesArray removeObjectsAtIndexes:indexSet];
Note that UICollectionView (available since iOS 6) might be better suited to display
multiple images per row.