1. 程式人生 > >背景檢視上點選事件與tableView衝突的解決辦法

背景檢視上點選事件與tableView衝突的解決辦法

解決辦法:
1.
cell新增點選手勢,通過手勢的方法實現
-
(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
   
    UITableViewCell *cell =
[tableView dequeueReusableCellWithIdentifier:reusedCell];
    cell.separatorInset = UIEdgeInsetsMake
(0, 0, 0, 0);
    cell.contentView.backgroundColor = ZCHexColor
(@"#f2f2f2");
   
    UITapGestureRecognizer *tap =
[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(labelAction:)];
    UILabel *title =
[[UILabel alloc] initWithFrame:CGRectMake(0, 0, LMWID-20, 54)];
    title.backgroundColor =
[UIColor clearColor];
    title.tag = 1022 + indexPath.row
; [title addGestureRecognizer:tap];
    title.userInteractionEnabled = YES
;
    title.textColor = ZCHexColor
(@"#333333");
    title.textAlignment = NSTextAlignmentCenter
; [cell.contentView addSubview:title];
    title.text =
[NSString stringWithFormat:@"%@",_dataSource[indexPath.row]];
   
    cell.textLabel.text = @"
舒服舒服";
     return cell
;
   
}

-
(void)labelAction:(UIGestureRecognizer *)ges {
    if
(self.select) {
        self.select
(ges.view.tag - 1022); [self removeFromSuperview];
    }
}

2.
tableView新增點選手勢,
UITapGestureRecognizer *tap =
[[UITapGestureRecognizer alloc] init];
tap.delegate = self
;[self.tableView addGestureRecognizer:tap];遵循手勢協議 UIGestureRecognizerDelegate ,然後重寫代理方法