ios – UITableViewCell删除按钮不会消失

栏目: IOS · 发布时间: 5年前

内容简介:哦,因为…的爱我没有打电话给[super prepareForReuse];在我的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子类中.

啊.

翻译自:https://stackoverflow.com/questions/20305084/uitableviewcell-delete-button-not-disappearing


以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

数据结构与算法分析

数据结构与算法分析

(美)(C.A.谢弗)Clifford A.Shaffer / 电子工业出版社 / 1998-8 / 35.00元

本书综合“数据结构与算法”的知识梳理、习题解答及上机辅导等于一身;精心挑选了覆盖教学大纲的五百多道题目,并且提供所有题目的参考答案;对于较难的算法和上机题,给出了详细的分析和说明;对于学习的重点和难点、易犯的错误、题目的难易和重要性,以及国内教材的差异等都给出了必要的说明。 本书可给使用各种教材讲授和学习“数据结构与算法”(或者“数据结构”)的师生参考,是系统复习该课程和准备应考计算......一起来看看 《数据结构与算法分析》 这本书的介绍吧!

MD5 加密
MD5 加密

MD5 加密工具

XML 在线格式化
XML 在线格式化

在线 XML 格式化压缩工具