iOS tableView的cell上添加控件,上拉出现控件复的解决方法

1、给控件添加tag值

- (void)Report:(LSXCommunityCell *)cell{
        self.dropView = [[PGGDropView alloc] initWithFrame:CGRectMake(200, 150 ,100, 200) withTitleArray:@[@"屏蔽此信息",@"举报该用户"]];
        [self.dropView beginAnimation];
        self.dropView.delegate = self;
        self.dropView.tag=100;
        [cell.contentView addSubview:self.dropView];    
}

2、在-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath方法中,添加
[[cell viewWithTag:100] removeFromSuperview];

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    // 通过indexPath创建cell实例 每一个cell都是单独的
     LSXCommunityCell *cell=[tableView dequeueReusableCellWithIdentifier:_Identifier];
    [[cell viewWithTag:100] removeFromSuperview];
    
    if (cell == nil) {
        //重构Cell的时候,通过 _Identifier判断是否创建打电话按钮
        cell = [[LSXCommunityCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:_Identifier];
    }
    [[cell viewWithTag:100] removeFromSuperview];
    cell.selectionStyle=UITableViewCellSelectionStyleNone;
    cell.delegate=self;

    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    if(self.dataArray.count>0){
        _model =self.dataArray[indexPath.row];
        cell.Model=_model;
        __weak typeof(self) weakSelf = self;
        cell.ReportBlock = ^(LSXCommunityCell *cell) {
            [weakSelf Report:cell]; 
        };
        cell.CommunityIdBlock = ^(NSString *str) {
            _idStr =str;
        };
        cell.bjbrPhoneBlock = ^(NSString *str) {
            _bjbrPhoneStr=str;
        };
    }
    return  cell;
}
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容