I use UISegmentedControl to switch a UITableView between two datasets (think favorites and duplicates). Pressing a segmented control reloads the table view with another dataset.
[self.tableView reloadSections:[NSIndexSet indexSetWithIndex:0] withRowAnimation:anim];
When a user deletes a row, it works fine. HOWEVER , when a user switches datasets through a segmented control, DELETED CELL is reused without changing its appearance (ie the red DELETE button still exists, and the contents of the row are nowhere to be seen), This seems to be the opposite problem. which most people see that the delete button does not appear.
This is the removal code:
- (UITableViewCellEditingStyle) tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath { return UITableViewCellEditingStyleDelete; } - (void) tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath { if (editingStyle == UITableViewCellEditingStyleDelete) { if ([self.current isEqualTo:self.favorites]) { Favorite *fav = self.favorites[indexPath.row]; NSMutableArray *mut = [self.favorites mutableCopy]; [mut removeObjectAtIndex:indexPath.row]; self.favorites = mut; self.current = self.favorites; [self.tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic]; } } }
The tableview has a single selection and self.tableView.editing == NO . I also tried to use [self.tableView reloadData] and remove / insert the difference in rows from one data set to the next. Nothing works.
UITableViewCell I use no backgroundView or selectedBackgroundView prefixes
[EDIT]
Changed the value of segmented control:
- (IBAction)modeChanged:(id)sender { if (self.listMode.selectedSegmentIndex == 1) { self.current = self.favorites; } else { self.current = self.recents; }
ios uitableview ios7
Stephen Furlani
source share