简体   繁体   English

UITableView在搜索时从单元格中删除复选标记

[英]UITableView removing checkmark from cell on search

I am using a UITableView to display some items and i have implemented a UISearchBar to this UITableView . 我正在使用UITableView显示一些项目,并且已经对此UITableView实现了UISearchBar

If the user presses the cell, a checkmark appears (accessory type of the cell is changed) and when pressed again the checkmark accessory disappears. 如果用户按下该单元格,则会出现一个选中标记(该单元格的附件类型已更改),再次按下该复选标记时,附件将消失。

My problem is when the user searches using the search bar, all the checked cells are not checked anymore, no more checked cells at all. 我的问题是,当用户使用搜索栏进行搜索时,不再选中所有选中的单元格,根本不再选中所有单元格。

I've been trying to fix this and searching for it for a while but no results ... 我一直在尝试修复此问题并搜索了一段时间,但没有结果...

Any help ?? 有帮助吗??

Thanks you. 谢谢。

That is because your table view where you put the checkmarks and the table view that you see after you enter something in the search bar is not same. 这是因为您放置复选标记的表格视图和在搜索栏中输入内容后看到的表格视图是不同的。 To have the same check marks on the search table view cells, you need to explicitly add the checkmarks. 要在搜索表视图单元格上具有相同的复选标记,您需要显式添加复选标记。

I can't see the way you are adding and removing check marks. 我看不到您添加和删除复选标记的方式。 So, in theory, what you need is a way to know which cells have check marks. 因此,从理论上讲,您需要的是一种知道哪些单元格带有复选标记的方法。 So, let's assume you have an array of items and a parallel array which holds the 1 or 0 to signal if the items have the check marks when 1 means check marked and 0 means no check mark. 因此,假设您有一个项目数组和一个并行数组,其中包含1或0,以在项目1表示选中标记而0表示没有复选标记时发信号表示项目是否带有复选标记。

Let's call this parallel array, checkMarkSignalArray. 我们将此并行数组称为checkMarkSignalArray。 Now, in your cellForRowAtIndexPath method, you can do something like- 现在,在您的cellForRowAtIndexPath方法中,您可以执行以下操作:

if(self.resultSearchController.active){
    cell.textLabel.text = [self.filteredItemsArray objectAtIndex:indexPath.row];
    if([self.checkMarkSignalArray objectAtIndex:indexPath.row]){
        cell.accessoryType = UITableViewCellAccessoryCheckmark;
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM