简体   繁体   中英

UITableViewCell accessory is not updating with searchResults

i added a check mark accessory on my tableView with this code :-

 override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath){

    if (PFUser.currentUser()?.objectForKey("userType")) as? String != "Std"{

    let cell = tableView.cellForRowAtIndexPath(indexPath) as! UsersTableViewCell

    if (cell.accessoryType == UITableViewCellAccessoryType.Checkmark){

        cell.accessoryType = UITableViewCellAccessoryType.None;


        selectedTextLabels[indexPath] = nil


     }else{
        cell.accessoryType = UITableViewCellAccessoryType.Checkmark;

        if (cell.accessoryType == UITableViewCellAccessoryType.Checkmark){

            if let Id = cell.channelIDLbl?.text {
                selectedTextLabels[indexPath] = Id

            }

         }
     }

   favoriteValues = Array(selectedTextLabels.values)

    print("\(favoriteValues)  outside")
}
}

its working fine on first tap i am able to assign a checkmark and again hitting the same cell removes that checkmark as desired but the problem is that when am using the searching function this checkmarks are just stuck at their indexes (search results are updating but not the accessories ) maybe is it happening because of this line selectedTextLabels[indexPath] because i am adding the accessory on selected indexPath not with the value which is inside the cell so how can i add this accessory on values instead of indexPath or there's any other way for doing it ?? if anybody knows then please guide me

PS - if my question's details are not enough then please let me know i'll fix it , thanks :)

请注意单元格的重用。如果上下滚动表格视图,则可能是单元格发生了变化。这是因为单元格上的数据在重用时不会清除。换句话说,您不应检查如果您没有意识到“准备重用”的方法(在此方法中,这是清理数据的最佳时间)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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