UITableView - 在编辑模式下重用单元格

sol*_*eil 4 uitableview ios

我发现如果你将表格视图设置为编辑模式,在删除一行后滚动表格时,单元格编辑控件(左边的红色减号)处于随机状态(垂直或水平)滚动表格时的单元格.大概是因为我正在重复使用这样的单元格:

cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
Run Code Online (Sandbox Code Playgroud)

如何强制编辑控件为每个单元格处于正确状态?它应始终处于默认的水平状态,除非我点击它以删除单元格.

编辑:这是单元格代码:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *cellIdentifier = @"WhateverIdentifier";
    MyCell *cell = nil;

    //This IF statement fixes the problem, but then I'm not reusing the cells
    if (!tableView.isEditing) {
        cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    }

    if (!cell) {
        cell = [[[NSBundle mainBundle] loadNibNamed:@"MyCell" owner:self options:nil] objectAtIndex:0];

    }

    //customize cell

    return cell;
}
Run Code Online (Sandbox Code Playgroud)

Nun*_*has 7

你在调用自定义单元格[super prepareForReuse]的方法prepareForReuse吗?

这解决了我的问题.