0

Hi i have been searching around to find a way to remove a static cell with animation but i have not found a solution to the problem. I have also tried: [tableView deleteRowsAtIndexPaths:[self.taskArray objectAtIndex:indexPath.row] withRowAnimation:UITableViewRowAnimationFade]; but no success.

2 Answers2

0

As your tableview is static, you cannot use deleteRowsAtIndexPath. The best option would probably be to migrate your data into a dataSource method for the tableview.

If this is impossible, then this answer ("UITableView set to static cells. Is it possible to hide some of the cells programmatically?") gives that the best method is to use the third party library

StaticDataTableViewController 2.0 (https://github.com/xelvenone/StaticDataTableViewController).

Otherwise you have to use the somewhat hacky method of changing the row height to 0.

Community
  • 1
  • 1
mginn
  • 16,036
  • 4
  • 26
  • 54
0

You need to hide cell before it is shown, in UITableViewDelegate's tableView:willDisplayCell:forRowAtIndexPath: method. This is the last method in your control where you can manipulate the cell display. It does not remove the space the cell takes, so another thing you can try is to set cell row's height to 0 using the tableView:heightForRowAtIndexPath: method of the same protocol.

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
      UITableViewCell *cell = [super tableView:tableView cellForRowAtIndexPath:indexPath];
      if (yourCell) {
          return 0;
      } else {
      return [super tableView:tableView heightForRowAtIndexPath:indexPath];
      }
   }
Avi
  • 2,196
  • 18
  • 18