iPhone dev: UITableView Cell's appreance modified when scrolling
I'm working on an iPhone application. This is a tab bar application, containing a navigation view controller within one particular tab. I have a table view in t开发者_如何学Gohe navigation view controller. In this groupe table, I need to add some UISwitch to some particular items. for instance, I have the following sections:
- accounts
- twitter (&)
- facebook (&)
- publication
- twitter (*)
- facebook (*)
- linkedIn (*)
- connection
- stay connected (*)
- about
- about
I need to have the UISwitch for the ones with the * but not for the other ones. I manage to add the UISwitch for thoses ones using condition on indexPath in the tableView:cellForRowAtIndexPath methods. BUT... when I scroll the view... the UISwitch are added to some other items (the one with the & above).
Could you please help ?
Thanks a lot,
Luc
It almost certainly is a problem with your code for cell reuse.
When you dequeue a cell to reuse it, it is not reset to a fresh state, instead it still has a UISwitch if a UISwitch was added to it before.
So whenever you dequeue a cell for reuse, you will need to assume that it might have a UISwitch subview, and remove that subview if you don't want it before you return the cell.
精彩评论