简体   繁体   中英

Issue on UITableViewCell custom class and UITableView scroll

I created a custom class of UITableViewCell with some variables for different state on UIGestureRecognizer.

For exemple :

class CustomClass : UITableViewCell {
    var isDisabled : Bool! = false
}

I have a swipe gesture to detect that the user want disabled the cell. So when the user swipe, I set my variable "isDisabled" to true.

Everything works fine until here.

But, if the first row has the variable "isDisabled" to true and I scroll in my tableView, the first row load at the bottom of the page has the variable "isDisabled" to true too, but the user don't say that he want this cell disabled.

So, have you any idea how I can solved my problem ?

Thanks

The issue you explain is regarding the reuse cells bahaviour of the UITableView . You can solve in different ways, I'll try to explain you one of them:

  • You can create a collection ( Array , or something else) of Bool for example, with the size of the numbers of cells in your UITableView and whenever you detect a swipe gesture mark the position in the array for the indexPath.row to true or false depends of it state. This keep the status of the cells for each index.

I hope this help you.

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