ios – 应用程序在UItableCellSection上长按崩溃

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    static NSString *simpleTableIdentifier = @"cell";

    simpleCell = [self.dashboardListView dequeueReusableCellWithIdentifier:simpleTableIdentifier];

    if (simpleCell == nil) {

        simpleCell = [[SimpleTableCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier];
        simpleCell.selectionStyle = UITableViewCellSelectionStyleNone;

    }

    ///tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(sectionTapped)];
    ///[simpleCell.contentView addGestureRecognizer:tap];

    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    [button setFrame:simpleCell.frame];
    [button addTarget:self action:@selector(sectionTapped) forControlEvents:UIControlEventTouchUpInside];
    [button setBackgroundColor:[UIColor clearColor]];
    [simpleCell.contentView addSubview:button];

    NSDictionary *dict = [cellnames objectAtIndex:section];

    simpleCell.cellName.text = (NSString *)[dict valueForKey:@"cellname"];
    simpleCell.count.text = [[countArray objectAtIndex:section]stringValue];


    return simpleCell;

}

上面的代码工作正常.

问题是: – 当我长按tableView上的simpleCell时崩溃了.

我正在收到崩溃日志

*** -[SimpleTableCell hash]: message sent to deallocated instance 0x7f86dc0b2420`

任何建议都非常感谢.

谢谢,

最佳答案 你可能想试试

cell.contentView.userInteractionEnabled = NO;
有同样的问题.禁用userInteraction为我解决.

点赞