IOS7 UITableView a row is deleted after the delete row is deleted the next row of the Click event will be ignored workaround

Source: Internet
Author: User

?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 - (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath {     returnUITableViewCellEditingStyleDelete; }- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {     if (editingStyle == UITableViewCellEditingStyleDelete)     {         [self.items removeObjectAtIndex:indexPath.row];         [tableView reloadData];     } }- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {     NSLog(@"Row %@ tapped.", self.items[indexPath.row]); }在ios6环境下,上段代码运行正常。但是在ios7环境下,我做了如下操作:当tableview中的一行被删除并更新tablview后,被删除行的下一行的点击事件将被忽略,导致点击该行无反应(<span style="color: rgb(255, 0, 0);">双击才有反应</span>)。很奇怪是不是,下面将解释原因。 当tableview中的某行被选中删除后,tableview将处于编辑(editing)状态,所以你需要将tableview中的状态更换成选择(selection)模式,更改代码如下:- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {   if (editingStyle == UITableViewCellEditingStyleDelete)   {     [self.items removeObjectAtIndex:indexPath.row];    // Turn off editing state here     tableView.editing = NO;    [tableView reloadData];   } }

  

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.