Reputation:
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
P.S. - if my question's details are not enough then please let me know i'll fix it , thanks :)
Upvotes: 1
Views: 151
Reputation: 6379
Pay attention to the reuse of cell.If you scroll the table view up and down,maybe the cell changes.This is because the data on the cell will not clean up when it is reused.In another words,you shouldn't check the data of a cell if you didn't realize the 'prepare for reuse ' method.(In this method,it's the best time to clean up data)
Upvotes: 0