IPhone developer-delete a row in Uitableview in ios7 environment and ignore click events

Source: Internet
Author: User

The following code is used to record the selected rows when you click a row in the selected tableview. When you scan and delete a row on the left, it deletes the row of data and updates the data in Uitableview.

@interface DummyTableViewController : UITableViewController@property (nonatomic, strong) NSMutableArray *items;@end@implementation DummyTableViewController- (instancetype)initWithStyle:(UITableViewStyle)style{    self = [super initWithStyle:style];    if (self)    {        _items = [ @[ @"A", @"B", @"C", @"D", @"E" ] mutableCopy];    }    return self;}- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{    return 1;}- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{    return [self.items count];}- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{    UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:nil];    cell.textLabel.text = self.items[indexPath.row];    return cell;}- (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]);}

In the ios6 environment, the previous Code follows the expectation described above. However, in the ios7 environment, I performed the following operations: When a row in tableview is deleted and updated to tablview, The Click Event of the next row of the deleted row is ignored, as a result, clicking this row does not respond. It's strange, isn't it? The reason is explained below.

When a row in tableview is selected and deleted, tableview will be in the editing status. Therefore, you need to change the status in tableview to the selection mode. The code for changing this mode is as follows:

- (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];  }}


Note: Due to my limited level, translation errors are inevitable. If you have any errors, please correct them and modify them as soon as possible.


Original article: http://stackoverflow.com/questions/19364409/uitableviewcontroller-ignores-tap-after-deleting-row-in-ios7

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.