ios – UITableViewCell删除按钮不会消失

我正在使用UISegmentedControl在两个数据集之间切换UITableView(想想收藏夹和最近的收藏夹).点击分段控件会使用不同的数据集重新加载tableview.
[self.tableView reloadSections:[NSIndexSet indexSetWithIndex:0] withRowAnimation:anim];

用户滑动以删除行时,它可以正常工作.然而,当用户通过分段控件切换数据集时,DELETED CELL会在不改变其外观的情况下被重复使用(即红色的“DELETE”按钮仍然存在且行内容无处可见).这似乎是大多数人看到的相反问题,即删除按钮没有出现.

这是删除代码

- (UITableViewCellEditingStyle) tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return UITableViewCellEditingStyleDelete;
}

- (void) tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (editingStyle == UITableViewCellEditingStyleDelete)
    {
        if ([self.current isEqualTo:self.favorites])
        {
            Favorite *fav = self.favorites[indexPath.row];

            NSMutableArray *mut = [self.favorites mutablecopy];
            [mut removeObjectAtIndex:indexPath.row];
            self.favorites = mut;
            self.current = self.favorites;
            [self.tableView deleteRowsAtIndexPaths:@[indexPath]
                                  withRowAnimation:UITableViewRowAnimationAutomatic];
        }
    }

}

tableview设置为single select,self.tableView.editing == NO.我也尝试使用[self.tableView reloadData]并删除/插入从一个数据集到下一个数据集的行差异.两者都不起作用.

我正在使用的UITableViewCell不提供backgroundView或selectedBackgroundView

[编辑]

分段控制值已更改:

- (IBAction)modeChanged:(id)sender
{
    if (self.listMode.selectedSegmentIndex == 1)
    {
         self.current = self.favorites;
    }
    else 
    {
        self.current = self.recents;
    }
    // Tryin this:
    [self.tableView reloadData];
    // Tried this:
    // [self.tableView reloadSections:[NSIndexSet indexSetWithIndex:0] withRowAnimation:UITableViewRowAnimationFade];
}

// Only 1 Section per table
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section;
{
    return [self.current count];
}

解决方法

哦,因为…的爱

我没有打电话给[super prepareForReuse];在我的UITableViewCell子类中.

啊.

相关文章

UITabBarController 是 iOS 中用于管理和显示选项卡界面的一...
UITableView的重用机制避免了频繁创建和销毁单元格的开销,使...
Objective-C中,类的实例变量(instance variables)和属性(...
从内存管理的角度来看,block可以作为方法的传入参数是因为b...
WKWebView 是 iOS 开发中用于显示网页内容的组件,它是在 iO...
OC中常用的多线程编程技术: 1. NSThread NSThread是Objecti...