UITableViewCell删除按钮不会消失

 wiggin 发布于 2023-02-13 17:00

我正在使用a 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设置为单选,和self.tableView.editing == NO.我也尝试过使用[self.tableView reloadData]和删除/插入从一个数据集到下一个数据集的行差异.两者都不起作用.

UITableViewCell我使用的是不供应backgroundViewselectedBackgroundView


[编辑]

分段控制值已更改:

- (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];
}

Stephen Furl.. 21

哦,因为...的爱

我没有[super prepareForReuse];在我的UITableViewCell子类中调用.

啊.

1 个回答
  • 哦,因为...的爱

    我没有[super prepareForReuse];在我的UITableViewCell子类中调用.

    啊.

    2023-02-13 17:03 回答
撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有