0

我创建了一个自定义单元格,单击后它应该显示一个弹出窗口。但是,当它成功运行时,似乎会产生一个我无法单击删除按钮的问题。在此处输入图像描述

似乎我UITapRecognizer取代了我的删除方法。(意味着当我单击删除按钮时会显示弹出窗口)

知道如何解决这个问题吗?

下面是我在单元格中处理点击的代码(OfficeCell.m

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
    UITapGestureRecognizer *tapGestureRecognizer = [[UITapGestureRecognizer alloc]     initWithTarget:self action:@selector(openOfficePopover)];
    [tapGestureRecognizer setNumberOfTapsRequired:1];
    [self setUserInteractionEnabled:YES];
    [self addGestureRecognizer:tapGestureRecognizer];

    self.textLabel.font = [UIFont boldSystemFontOfSize:15];
    self.textLabel.textColor = mRgb(0x3a, 0x6c, 0x99); 

     }
    return self;
}

下面是我处理删除的代码ViewController

- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
   {
       // Return NO if you do not want the specified item to be editable.

       NSInteger section = [indexPath section];
       if (section ==1 )
       {
          return YES;
       }
       return NO;
  }


- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {

    if (editingStyle == UITableViewCellEditingStyleDelete)
    {
        // Delete the row from the data source
        NSInteger section = [indexPath section];

        if(section == 1)
        {
            [_sectionOffice removeObjectAtIndex:indexPath.row];
        }
        [self.formView reloadData];
    }
}
4

1 回答 1

2

只要意识到修复应该非常简单:

更改 2 行代码解决问题:

从 :

[self setUserInteractionEnabled:YES];
[self addGestureRecognizer:tapGestureRecognizer];

至 :

[self.contentView setUserInteractionEnabled:YES];
[self.contentView addGestureRecognizer:tapGestureRecognizer];
于 2013-09-19T09:47:37.783 回答