IOS7 UITableView一行滑动删除后 被删除行的下一行的点击事件将被忽略解决办法

来源:互联网 发布:nginx 访问报404 编辑:程序博客网 时间:2024/06/07 06:24
  1. - (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
  2. {        returnUITableViewCellEditingStyleDelete;
  3. }
  4. - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
  5. {        if (editingStyle == UITableViewCellEditingStyleDelete)        {        [self.items removeObjectAtIndex:indexPath.row];        [tableView reloadData];        }
  6. }
  7. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  8. {        NSLog(@"Row %@ tapped.", self.items[indexPath.row]);
  9. }
  10. 在ios6环境下,上段代码运行正常。但是在ios7环境下,我做了如下操作:当tableview中的一行被删除并更新tablview后,被删除行的下一行的点击事件将被忽略,导致点击该行无反应(双击才有反应)。很奇怪是不是,下面将解释原因。
  11. 当tableview中的某行被选中删除后,tableview将处于编辑(editing)状态,所以你需要将tableview中的状态更换成选择(selection)模式,更改代码如下:
  12. - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
  13. { if (editingStyle == UITableViewCellEditingStyleDelete) {        [self.items removeObjectAtIndex:indexPath.row];        // Turn off editing state here        tableView.editing = NO;        [tableView reloadData]; }
  14. }
0 0