开发者

iPhone dev: UITableView Cell's appreance modified when scrolling

开发者 https://www.devze.com 2023-01-17 06:45 出处:网络
I\'m working on an iPhone application. This is a tab bar application, containing a navigation view controller within one particular tab.

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 (&)
    • linkedIn
  • 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号